System and Method for Advanced Polyhedral Loop Transformations of Source Code in a Compiler

ABSTRACT

A system and method for advanced polyhedral loop transformations of source code in a compiler are provided. The mechanisms of the illustrative embodiments address the weaknesses of the known polyhedral loop transformation based approaches by providing mechanisms for performing code generation transformations on individual statement instances in an intermediate representation generated by the polyhedral loop transformation optimization of the source code. These code generation transformations have the important property that they do not change program order of the statements in the intermediate representation. This property allows the result of the code generation transformations to be provided back to the polyhedral loop transformation mechanisms in a program statement view, via a new re-entrance path of the illustrative embodiments, for additional optimization.

GOVERNMENT RIGHTS

This invention was made with Government support under the DefenseAdvanced Research Projects Agency (DARPA), HR0011-07-9-0002. THEGOVERNMENT HAS CERTAIN RIGHTS IN THIS INVENTION.

BACKGROUND

1. Technical Field

The present application relates generally to an improved data processingsystem and method. More specifically, the present application isdirected to a system and method for advanced polyhedral looptransformations of source code in a compiler.

2. Description of Related Art

Generating computer code that is efficiently processed (i.e.,“optimized”) is one of the most important goals in software design andexecution. Computer code which performs the desired function accuratelyand reliably but too slowly (i.e., code which is not optimized) is oftendiscarded or unused by computer users.

As those of ordinary skill in the art are aware, most source code (i.e.,that code which is a human readable form) is typically converted intoobject code, and thereafter an executable application, by use of acompiler and a linker. The executable application is in a form andlanguage that is machine readable (i.e., capable of being interpretedand executed by a computer). Other languages, such as Java availablefrom Sun Microsystems, Inc. of California, USA, may be in source codeform that is, on execution, transformed into a form understood by acomputer system which then executes the transformed instructions. In anycase, the source code, when transformed into a form capable of beingunderstood and executed by a computer system, is frequently optimized.That is, a transformation is performed such that the instructions areperformed more efficiently (i.e., optimized) and, hopefully, without anyundue delay.

One common structure found in source code that is optimized, during thecompilation process to transform source code into executable code, isthe loop. Loops are used to repeat one or more operations orinstructions. Loops may be provided as single, non-nested loops, ornested loops, i.e. loops within loops. For example, an array may be usedto store the purchase price of individual articles (e.g., where thei^(th) element in the array A is denoted, in Fortran, as A(i)—othersimilar notations are used in other languages) generate a singleinstruction to add each of the purchase prices together (e.g.,sum=A(1)+A(2)+ . . . +A(n)). This however would take the programmer sometime to code and is not easily adapted to the situation where thecomputer programmer does not know, at development time, the number ofarticles in the array. That is, when the number of elements in the arraycan only be determined at run time (i.e., during execution).Accordingly, the loop was developed to repeat an operation (e.g.,sum=sum+A(i))) where the induction variable, i, is changed for eachiteration. Other forms of loops are known and are equally applicable.

However, when the instructions of a loop are transformed into machinereadable code (e.g., executable code), the executed instructions may notbe processed efficiently. For the example above, some computer systemsmay require that the processor fetch from memory, rather than from aregister or cache memory, the various elements of the array “A”.Fetching data from memory requires the processor to wait while the datais retrieved thereby increasing the latency of the program execution.Also, while loops may be an efficient way to write certain repetitivesource code operations, a loop does insert additional operations thatwould not be present if the repetitive operations were replicated. Theseadditional operations (e.g., branching operations) are considered to bethe loop “overhead”.

To address some of the inefficiencies in processing loops, variousoptimization techniques have been created and applied. Examples of thesevarious optimization techniques include loop inversion, loop skewing,loop tiling, unrolling and jamming, and the like. For example, withunrolling and jamming (hereinafter “unrolling”) a portion of the loop isreplicated, or “unrolled,” and the replicated portions are inserted, or“jammed,” into the code. Typically, when the unroll and jam looptransformation technique is applied to the outer loop of a nested looppair, the outer loop's induction variable (e.g., “i”) is advanced only afew times (the number of times being governed by a parameter referred toas the unroll factor—UF) rather than completely during the unrollingportion of this optimization technique. During the jamming portion ofthis technique, the inner loop would be replicated “UF” times. Personsof ordinary skill in the art will appreciate that the replicated loopbodies are not identical but only similar. In the replicated loopbodies, portions of the loop bodies which use the induction of the outerloop will be advanced as required (e.g., if the loop body includedreference to array element A(i), where “i” is the outer loop inductionvariable, a replicated loop body would include reference to the nextrequired array element—A(i+1)). The unroll and jam technique effectivelyreorders the calculations being performed in the nested loop.

Typically, such optimizations are performed with regard to a compiler'sintermediate representation of the source code, e.g., an abstract syntaxtree. The abstract syntax tree is a finite, labeled, directed tree,where the internal nodes are labeled by operators, and the leaf nodesrepresent the operands of the operators. The abstract syntax tree (AST)is used in a parser as an intermediate between a parse tree and a datastructure, the latter of which is often used as a compiler orinterpreter's internal representation of a computer program while it isbeing optimized and from which code generation is performed. ASTs areusually not appropriate for complex program restructuring since, whilesimple optimizations such as constant folding or scalar replacement maybe achieved without hard modifications of the data structures, morecomplex transformations such as loop inversion, skewing, tiling, etc.,modify the execution order, which is far away from the syntax. SeeCedric Bastoul, “Code Generation in the Polyhedral Model is Easier ThanYou Think,” PACT'13 IEEE International Conference on ParallelArchitecture and Compilation Techniques, pages 7-18, Juan-les-Pins,September 2004, which is hereby incorporated by reference.

The polyhedral model, which is based on a linear algebraicrepresentation of programs and transformations, was developed to addressthis issue. See Bastoul et al. “Putting Polyhedral Loop Transformationsto Work,” LCPC'16 International Workshop on Languages and Compilers forParallel Computers, LNCS 2958, pages 209-225, College Station, October2003, which is hereby incorporated by reference. The polyhedral model isbasically a plugin to the conventional compilation process. It startsfrom the AST by translating the program parts that fit the model into alinear-algebraic representation. A new execution order is then selectedby using a reordering function, e.g., using a schedule, placement orchunking function. Then, in a code generation step, an AST or new sourcecode is returned that implements the execution order implied by thereordering function.

As an example of the polyhedral transformation consider the syntacticform of a polynomial multiplication kernel as represented in FIG. 1A.See Vasilache et al., “Polyhedral Code Generation in the Real World,”INRIA, 2006, available at http://hal.inria.fr/inria-00001106/en/. Thisexample is concerned only with the control aspects of the program sourcecode with the two computational statements (array assignments) beingreferred to herein by their names S1 and S2. The polyhedraltransformation model considers statement instances. For each statement,the iteration domain where every statement instance belongs isconsidered. The iteration domains are described using affine constraintsthat can be extracted from the program control. For example, theiteration domain of statement S1, referred to as D_(S1), is the set ofvalues (i) such that 2≦i≦n. As shown in FIG. 1B, a matrix representationis used to represent such constraints: A*x+Ap*p≧0, where A is theiteration matrix, x is the iteration vector (composed of the loopcounters), Ap is the parameter matrix and p is the parameter vector(composed of the unknown constants and the scalar 1). Thus, in theexample of FIGS. 1A and 1B, D_(S1) is characterized by:

${{\begin{bmatrix}1 \\{- 1}\end{bmatrix} \cdot (i)} + {\begin{bmatrix}0 & {- 2} \\1 & 0\end{bmatrix} \cdot \begin{pmatrix}n \\1\end{pmatrix}}} \geq 0.$

In this framework, a transformation is a set of affine schedulingfunctions written θ(x)=T*x+Tp*p. Each statement has its own schedulingfunction which maps each runtime statement instance to a logicalexecution time. In the polynomial multiplication example of FIGS. 1A and1B, an optimizer may notice a locality problem and discover a good datareuse potential over array z, then suggest θ_(S1)(i)=(i) and

${\theta_{S2}\begin{pmatrix}i \\j\end{pmatrix}} = \left( {i + j + 1} \right)$

to achieve better locality. See Bastoul et al., “Improving Data Localityby Chunking,” CC'12 Intl. Conf. on Compiler Construction, LNCS 2622,pages 320-335, Warsaw, April 2003, which is hereby incorporated byreference, for a method to compute such functions. The intuition behindsuch transformation is to execute consecutively the instances of S2having the same i+j value (thus accessing the same array element of z)and to ensure that the initialization of each element is executed by S1just before the first instance of S2 referring to this element. Atransformation is applied in the polyhedral model by using thetransformation formula shown in FIG. 1C, where t is the time-vector,i.e. the vector of the scheduling dimensions. The resulting polyhedra,for the example, is shown in FIG. 1D with the additional dimension t.

Once the transformation has been applied in the polyhedral model, oneneeds to generate the target code. A syntax tree construction scheme,which may consist of a recursive application of domain projections andseparations, such as described in Bastoul “Code Generation in thePolyhedral Model is Easier Than You Think” and Quillere et al.,“Generation of Efficient Nested Loops from Polyhedra,” InternationalJournal of Parallel Programming, 28(5):469-496, October 2000, is appliedto the transformation. The final code is deduced from the set ofconstraints describing the polyhdera attached to each node in the AST.

In the above example, the first step is a projection onto the firstdimension t, followed by a separation into disjoint polyhedra as shownon the top of FIG. 2A. This builds the first loop level of the targetcode (the loops with iterator t shown in FIG. 2B). The same process isapplied onto the first two dimensions (on the bottom of FIG. 2A) tobuild the second loop level, and so on. The final code is shown in FIG.2B. Note that the separation step for two polyhedra needs threeoperations: D_(S1)-D_(S2), D_(S2)-D_(S1), and D_(S2)∩D_(S1), thus for nstatements, the worst case complexity is 3^(n).

The polyhedral loop transformation-based approach to compileroptimization addresses several weaknesses of the traditional loop-basedapproaches to source code optimization. The polyhedral looptransformation approach addresses non-perfectly nested loops, has aprecise instant-wise representation of data dependencies, and naturallysupports compositions of complex transformations. As a result, it candetect more parallelism and exploit more data locality for more complexloop nests than the traditional loop-based approaches.

However, while the polyhedral loop transformation-based approachprovides improved optimization of source code during the compilationprocess, it is not more widely used because of two main drawbacks.First, the code that is generated from the polyhedral representation isnot always optimal with regard to some optimization criteria. This meansthat code that has excellent properties, such as data-parallelism(meaning that the work within a given loop or set of loops is dataparallel and thus can be computed in parallel by possibly multiplethreads on possibly multiple processors) and data locality (meaning thedata needed to compute a specific amount of work generated by a givenloop or set of loops often reuses the same set of data or a set of datathat is collocated in memory) may be slowed down because of sub-parscalar performance (meaning that the generated code has high overheaddue to unnecessary checks, branch, loop bound computations, and/or anyother overheads) and/or unnecessary code bloat, i.e. an increase in thesize of the code due to compiler optimizations being run on the sourcecode. Second, transformations applied to a statement by currentpolyhedral loop transformation approaches necessarily touch allinstances of a given statement. This means that, for example, it is hardto express parallelism for a statement that is partially parallel, i.e.a statement that is parallel in all but a few boundary instances.Similarly, for data locality enhancement, requiring that tiling must beperformed on all instances of a statement, including the rarely executedboundary conditions, results in unnecessary code bloat as well asincreased loop overhead. Tiling is a loop optimization that aims atincreasing the data locality of a computation by cutting a large set ofcomputation, e.g. a 2 dimensional computation iterating over 0-1023times 0-1023 by a smaller set of computation on a smaller tile, e.g.0-63×0-63, where once the first tile is completed, one may then iterateover the second tile, e.g. 0-63×64-127, with this operation repeatingwith subsequent tiles until all of the original computation iscompleted.

SUMMARY

The illustrative embodiments provide a system and method for advancedpolyhedral loop transformations of source code in a compiler. Themechanisms of the illustrative embodiments address the weaknesses of theknown polyhedral loop transformation based approaches by providingmechanisms for performing code generation transformations on theintermediate representation (IR), e.g., an abstract syntax tree (AST),generated by the polyhedral loop transformation optimization of thesource code. These code generation transformations have the importantproperty that they do not change program order of the statements in theintermediate representation. This property allows the result of the codegeneration transformations, i.e. a new AST, to be provided back to thepolyhedral loop transformation mechanisms in a program statement view,via a new re-entrance path of the illustrative embodiments, foradditional optimization.

Such code generation transformations may induce statement splitting oraggregation, may modify domain and schedule components, and the like.However, they do so in a transparent manner ensuring strict equivalenceof the relative orders induced by the new schedules for all instances ofall statements. This strict equivalence involves program equivalence andschedule equivalence, i.e. only relative execution order of allinstances of statements is required and thus, is ensured via strictequivalence. Thus, the AST generated by the polyhedral looptransformation optimizations on the program statement view will beequivalent to the new AST generated by the code generation optimizationsapplied to this AST from a program and schedule equivalence standpoint.

Code generation transformations may include, for example, conditionalhoisting, kernel extraction, parallelism detection, modulo copypropagation. Each of these code generation transformations involvestaking two arguments, i.e. a list of AST nodes referred to by prefixvectors in a loop-centric view of the program (the prefix vector list)and a propagation mode that can be “any” (all the nodes in the AST arevisited), “prefix” (all the children of a given node are visited), or“exact” (only the specified node is visited). Based on the prefix vectorlist and the kind of propagation, a first pass of the AST is performedto flag the nodes that need to be processed. Thereafter, visitors areinstantiated and used to apply core functions of the code generationtransformations. The result of the code generation transformations is amodified or new AST that has lower control flow overhead. The codegeneration transformations do not modify the program semantics in anyway although they may result in different equivalent schedules afterregeneration.

The generated modified or new AST may then undergo program regeneration,which along with the code generation transformations makes thepolyhedral framework of the illustrative embodiments fully iterative.Program regeneration involves transforming the modified or new AST intoa stable program with respect to code generation. In order to generate astable program, each statement in the new stable program needs to haveits own domain that does not overlap with other instances of the sameoriginal statement. Each schedule must enforce the same relative orderwith respect to all other instances of any other statement. Furthermore,subsequent call to a separation algorithm in the program statement viewoptimizations of the compiler should result in the same AST asoriginally presented to the code generation transformations. In order toachieve all of these goals, schedule reconstruction, domainreconstruction, and domain stretching transformations are performed togenerate a new stable program. This new stable program may be fed backto the program statement view stage of the compiler for furtheroptimizations by the program statement view optimizations.

In one illustrative embodiment, a method is provided for optimizingprogram code. The method may comprise receiving source code for aprogram in a compiler and optimizing, in a loop optimization engine, thesource code for execution by a computing device. Optimizing the sourcecode may comprise generating a program statement view of the sourcecode, generating a program loop view of the source code based on theprogram statement view, and applying one or more code generationoptimizations to the program loop view of the source code to generate anoptimized program loop view of the source code. Optimizing the sourcecode may further comprise converting the optimized program loop view ofthe source code back into a first optimized program statement view ofthe source code through a re-entrance path, performing one or moreadditional optimizations on the first optimized program statement viewof the source code, and outputting resulting optimized code, as a resultof optimizing the source code, to the compiler for generation ofexecutable code to be executed on a computing device.

The one or more code generation optimizations may be applied toindividual nodes within the program loop view of the source code. Theone or more code generation optimizations may result in a lower controlflow overhead of the optimized program loop view of the source code whencompared to control flow overhead of the program loop view of the sourcecode. Moreover, the one or more code generation optimizations, in oneillustrative embodiment, do not modify a program order of statements inthe optimized program loop view from a program order present in theprogram statement view of the source code.

Converting the optimized program loop view of the source code into afirst optimized program statement view of the source code through are-entrance path may comprise retrieving an Alpha matrix, a Beta matrix,and a Gamma matrix for each statement in the optimized program loop viewand transforming the optimized program loop view into the firstoptimized program statement view using the Alpha, Beta, and Gammamatrices along with a remapping matrix that identifies how to transformthe optimized program loop view back to a program statement view. TheAlpha matrix represents a speed at which an associated statement isperformed along a given time dimension. The Beta matrix represents asequential interleaving of the associated statement along different loopdepths. The Gamma matrix represents a constant parametric shifting ofthe associated statement along each time dimension.

Applying one or more code generation optimizations to the program loopview of the source code to generate an optimized program loop view ofthe source code may comprise, for each statement in the optimizedprogram loop view, splitting a domain and schedule of the statement intoa plurality of sub-domains and sub-schedules based on instances of thestatement in the optimized program loop view such that the statementdoes not share a common representation with other statements in thefirst optimized program statement view. The one or more additionaloptimizations may be applied to each statement individually based on theseparate sub-domains and sub-schedules.

Applying the one or more code generation optimizations to the programloop view of the source code to generate an optimized program loop viewof the source code may further comprise generating a domain and schedulefor a kernel of the statements of the optimized program loop view. Thedomain and schedule for the kernel may be separate from the sub-domainand sub-schedules of the instances of the statements. The sub-domainsand sub-schedules may be generated by extracting a kernel of fusedstatements in the optimized program loop view such that a separatedomain and schedule for each boundary portion of the fused statements,where only one statement applies, is generated, and a separate domainand schedule for the kernel, where both statements apply, is generated.

The one or more code generation optimizations may comprise at least oneof simplification and unstretching, if hoisting, substitute modulo, orloop unrolling. Generating a program statement view of the source codemay comprise performing a polyhedral scan operation on the source codeto generate the program statement view. The re-entrance path maycomprise a polyhedral rescan module that rescans the optimized programloop view of the source code to generate the first optimized programstatement view from the optimized program loop view.

Performing one or more additional optimizations on the first optimizedprogram statement view of the source code may result in a secondoptimized program statement view of the source code. In such a case, themethod may further comprise converting the second optimized programstatement view of the source code into a second program loop view of thesource code and applying the one or more code generation optimizationsto the second program loop view to generate a second optimized programloop view of the source code.

In other illustrative embodiments, a computer program product comprisinga computer useable medium having a computer readable program isprovided. The computer readable program, when executed on a computingdevice, causes the computing device to perform various ones, andcombinations of, the operations outlined above with regard to the methodillustrative embodiment.

In yet another illustrative embodiment, a system is provided. The systemmay comprise a processor and a memory coupled to the processor. Thememory may comprise instructions which, when executed by the processor,cause the processor to perform various ones, and combinations of, theoperations outlined above with regard to the method illustrativeembodiment.

These and other features and advantages of the present invention will bedescribed in, or will become apparent to those of ordinary skill in theart in view of, the following detailed description of the exemplaryembodiments of the present invention.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention, as well as a preferred mode of use and further objectivesand advantages thereof, will best be understood by reference to thefollowing detailed description of illustrative embodiments when read inconjunction with the accompanying drawings, wherein:

FIG. 1A is a syntactic form of a polynomial multiplication kernel;

FIG. 1B is a matrix representation of the polynomial multiplicationkernel of FIG. 1A;

FIG. 1C is a transformation formula that is applied in the polyhedralmodel where t is the time-vector;

FIG. 1D is a polyhedra resulting from the application of thetransformation formula of FIG. 1C to the matrix representation in FIG.1B with the additional dimension t;

FIG. 2A illustrates a separation into disjoint polyhedra for codegeneration in accordance with a known operation;

FIG. 2B illustrates example final code obtained by using the separationoperation of FIG. 2A;

FIG. 3 is an exemplary representation of an exemplary distributed dataprocessing system in which aspects of the illustrative embodiments maybe implemented;

FIG. 4 is a block diagram of an exemplary data processing system inwhich aspects of the illustrative embodiments may be implemented;

FIG. 5 is an exemplary diagram illustrating a traditional orconventional polyhedral approach to source code optimization duringcompilation;

FIGS. 6A-6F are diagrams illustrating the program statement view andexamples of the loop optimizer 530 transformations that may be performedon the program statement view;

FIGS. 7A-7C illustrate a mapping using Quillere's projection anddecomposition technique;

FIG. 8 is an exemplary block diagram of an advanced polyhedral looptransformation mechanism in accordance with one illustrative embodiment;

FIG. 9 illustrates an example of a polyhedral loop transformation fusionoperation;

FIG. 10 illustrates the separation of fused loops into separaterepresentations for each portion of the fused loops such that therepresentations are not shared;

FIG. 11 is an example of pseudocode of an algorithm for applying codegeneration optimizations/transformations;

FIG. 12A represents an example of original code for illustrating aconditional hoisting operation in accordance with one illustrativeembodiment;

FIG. 12B represents the same code as in FIG. 12A with a gentle, or leastaggressive, mode of conditional hoisting having been performed inaccordance with one illustrative embodiment;

FIG. 12C represents the same code as in FIG. 12A with an aggressive modeof conditional hoisting having been applied in accordance with oneillustrative embodiment;

FIG. 13A represents an example of original code for illustrating akernel extraction operation in accordance with one illustrativeembodiment;

FIG. 13B illustrates skewing of the original code of FIG. 13A along afirst dimension in accordance with one illustrative embodiment;

FIG. 13C illustrates a result of the kernel extraction code generationoptimization/transformation in accordance with one illustrativeembodiment;

FIGS. 14A-14C are exemplary diagrams illustrating a manner forexpressing parallelism in source code in accordance with oneillustrative embodiment;

FIG. 15 is an exemplary diagram illustrating a transition graph foriterative polyhedral loop transformation optimizations in accordancewith one illustrative embodiment;

FIGS. 16A-16C are exemplary diagrams illustrate a large code growth thatmay occur as a byproduct of successive polyhedral rescan operations by apolyhedral rescan module and a successive operation of the codegeneration optimization/parallelism detection module;

FIGS. 17A-17C are exemplary diagrams illustrating an example of codeoptimization where two statements have had their speed accelerated by afactor of 3 in accordance with one illustrative embodiment;

FIGS. 18A-18F are exemplary diagrams illustrating code instability thatmay be introduced by a re-entrance path in a polyhedral looptransformation mechanism;

FIGS. 19A-19B are exemplary diagrams illustrating scattering domains forstatements S1 and S2 and a resulting stable AST^(P′) obtained using thescatter domain with stretching transformation of one illustrativeembodiment;

FIGS. 20A-20C are exemplary diagrams illustrating an example of domainstretching under re-entrance in accordance with one illustrativeembodiment;

FIG. 21 is a flowchart outlining an exemplary operation for utilizing are-entrance path to obtain further optimization of code in accordancewith one illustrative embodiment;

FIG. 22 is a flowchart outlining an exemplary operation for applying acode generation transformation algorithm in accordance with oneillustrative embodiment;

FIG. 23 is a flowchart outlining an exemplary operation for preservingstability of code in the presence of conditionals for re-entrance inaccordance with one illustrative embodiment; and

FIG. 24 is a flowchart outlining an exemplary operation for performingscatter domain stretching in accordance with one illustrativeembodiment.

DETAILED DESCRIPTION OF THE ILLUSTRATIVE EMBODIMENTS

The illustrative embodiments provide a system and method for advancedpolyhedral loop transformations of source code in a compiler. Themechanisms of the illustrative embodiments address the weaknesses of theknown polyhedral loop transformation based approaches by providingmechanisms for performing code generation transformations on theintermediate representation (IR), e.g., an abstract syntax tree (AST),generated by the polyhedral loop transformation optimization of thesource code. These code generation transformations have the importantproperty that they do not change program order of the statements in theintermediate representation. This property allows the result of the codegeneration transformations, i.e. a new AST, to be provided back to thepolyhedral loop transformation mechanisms in a program statement view,via a new re-entrance path of the illustrative embodiments, foradditional optimization. As such, the mechanisms of the illustrativeembodiments may be implemented in a stand-alone or distributed dataprocessing system in which a compiler is utilized to compile source codeinto executable code for execution on one or more data processingdevices.

For example, in a distributed data processing system, the source codemay be provided, such as by a client data processing device, to a serveror other data processing device that runs a compiler for compiling thesource code into executable code. The server or other data processingdevice may implement the mechanisms of the illustrative embodiments toperform polyhedral loop transformation optimizations on an intermediaterepresentation of the source code during such compilation. Alternative,the mechanisms of the illustrative embodiments may be implemented in thesame data processing device in which the source code is generated and/ororiginally provided. The following FIGS. 3-4 are provided as examples ofa distributed and/or stand-alone data processing system which may beused to implement the mechanisms of the illustrative embodiments.

With reference now to the figures and in particular with reference toFIGS. 3-4, exemplary diagrams of data processing environments areprovided in which illustrative embodiments of the present invention maybe implemented. It should be appreciated that FIGS. 3-4 are onlyexemplary and are not intended to assert or imply any limitation withregard to the environments in which aspects or embodiments of thepresent invention may be implemented. Many modifications to the depictedenvironments may be made without departing from the spirit and scope ofthe present invention.

With reference now to the figures, FIG. 3 depicts a pictorialrepresentation of an exemplary distributed data processing system inwhich aspects of the illustrative embodiments may be implemented.Distributed data processing system 300 may include a network ofcomputers in which aspects of the illustrative embodiments may beimplemented. The distributed data processing system 300 contains atleast one network 302, which is the medium used to provide communicationlinks between various devices and computers connected together withindistributed data processing system 300. The network 302 may includeconnections, such as wire, wireless communication links, or fiber opticcables.

In the depicted example, server 304 and server 306 are connected tonetwork 302 along with storage unit 108. In addition, clients 310, 312,and 314 are also connected to network 302. These clients 310, 312, and314 may be, for example, personal computers, network computers, or thelike. In the depicted example, server 304 provides data, such as bootfiles, operating system images, and applications to the clients 310,312, and 314. Clients 310, 312, and 314 are clients to server 304 in thedepicted example. Distributed data processing system 300 may includeadditional servers, clients, and other devices not shown.

In the depicted example, distributed data processing system 300 is theInternet with network 302 representing a worldwide collection ofnetworks and gateways that use the Transmission ControlProtocol/Internet Protocol (TCP/IP) suite of protocols to communicatewith one another. At the heart of the Internet is a backbone ofhigh-speed data communication lines between major nodes or hostcomputers, consisting of thousands of commercial, governmental,educational and other computer systems that route data and messages. Ofcourse, the distributed data processing system 300 may also beimplemented to include a number of different types of networks, such asfor example, an intranet, a local area network (LAN), a wide areanetwork (WAN), or the like. As stated above, FIG. 3 is intended as anexample, not as an architectural limitation for different embodiments ofthe present invention, and therefore, the particular elements shown inFIG. 3 should not be considered limiting with regard to the environmentsin which the illustrative embodiments of the present invention may beimplemented.

With reference now to FIG. 4, a block diagram of an exemplary dataprocessing system is shown in which aspects of the illustrativeembodiments may be implemented. Data processing system 400 is an exampleof a computer, such as hosts 310 in FIG. 3, in which computer usablecode or instructions implementing the processes for illustrativeembodiments of the present invention may be located.

In the depicted example, data processing system 400 employs a hubarchitecture including north bridge and memory controller hub (NB/MCH)402 and south bridge and input/output (I/O) controller hub (SB/ICH) 404.Processing unit 406, main memory 408, and graphics processor 410 areconnected to NB/MCH 402. Graphics processor 410 may be connected toNB/MCH 402 through an accelerated graphics port (AGP).

In the depicted example, local area network (LAN) adapter 412 connectsto SB/ICH 404. Audio adapter 416, keyboard and mouse adapter 420, modem422, read only memory (ROM) 424, hard disk drive (HDD) 426, CD-ROM drive430, universal serial bus (USB) ports and other communication ports 432,and PCI/PCIe devices 434 connect to SB/ICH 404 through bus 438 and bus440. PCI/PCIe devices may include, for example, Ethernet adapters,add-in cards, and PC cards for notebook computers. PCI uses a card buscontroller, while PCIe does not. ROM 424 may be, for example, a flashbinary input/output system (BIOS).

HDD 426 and CD-ROM drive 430 connect to SB/ICH 404 through bus 440. HDD426 and CD-ROM drive 430 may use, for example, an integrated driveelectronics (IDE) or serial advanced technology attachment (SATA)interface. Super I/O (SIO) device 436 may be connected to SB/ICH 404.

An operating system runs on processing unit 406. The operating systemcoordinates and provides control of various components within the dataprocessing system 400 in FIG. 4. As a client, the operating system maybe a commercially available operating system such as Microsoft® Windows®XP (Microsoft and Windows are trademarks of Microsoft Corporation in theUnited States, other countries, or both). An object-oriented programmingsystem, such as the Java™ programming system, may run in conjunctionwith the operating system and provides calls to the operating systemfrom Java™ programs or applications executing on data processing system400 (Java is a trademark of Sun Microsystems, Inc. in the United States,other countries, or both).

As a server, data processing system 400 may be, for example, an IBM®eServer™ pSeries® computer system, running the Advanced InteractiveExecutive (AIX®) operating system or the LINUX® operating system(eServer, pSeries and AIX are trademarks of International BusinessMachines Corporation in the United States, other countries, or bothwhile LINUX is a trademark of Linus Torvalds in the United States, othercountries, or both). Data processing system 400 may be a symmetricmultiprocessor (SMP) system including a plurality of processors inprocessing unit 406. Alternatively, a single processor system may beemployed.

Instructions for the operating system, the object-oriented programmingsystem, and applications or programs are located on storage devices,such as HDD 426, and may be loaded into main memory 408 for execution byprocessing unit 406. The processes for illustrative embodiments of thepresent invention may be performed by processing unit 406 using computerusable program code, which may be located in a memory such as, forexample, main memory 408, ROM 424, or in one or more peripheral devices426 and 430, for example.

A bus system, such as bus 438 or bus 440 as shown in FIG. 4, may becomprised of one or more buses. Of course, the bus system may beimplemented using any type of communication fabric or architecture thatprovides for a transfer of data between different components or devicesattached to the fabric or architecture. A communication unit, such asmodem 422 or network adapter 412 of FIG. 4, may include one or moredevices used to transmit and receive data. A memory may be, for example,main memory 408, ROM 424, or a cache such as found in NB/MCH 402 in FIG.4.

Those of ordinary skill in the art will appreciate that the hardware inFIGS. 3-4 may vary depending on the implementation. Other internalhardware or peripheral devices, such as flash memory, equivalentnon-volatile memory, or optical disk drives and the like, may be used inaddition to or in place of the hardware depicted in FIGS. 3-4. Also, theprocesses of the illustrative embodiments may be applied to amultiprocessor data processing system, other than the SMP systemmentioned previously, without departing from the spirit and scope of thepresent invention.

Moreover, the data processing system 400 may take the form of any of anumber of different data processing systems including client computingdevices, server computing devices, a tablet computer, laptop computer,telephone or other communication device, a personal digital assistant(PDA), or the like. In some illustrative examples, data processingsystem 400 may be a portable computing device which is configured withflash memory to provide non-volatile memory for storing operating systemfiles and/or user-generated data, for example. Essentially, dataprocessing system 400 may be any known or later developed dataprocessing system without architectural limitation.

With the data processing systems of FIGS. 3-4, assuming a distributeddata processing system implementation, source code may be provided to adata processing system 400, such as server 304 in FIG. 3, from a clientdata processing device, such as client 310 in FIG. 3, or the like, forcompilation into an executable program. The mechanisms of theillustrative embodiments improve upon known compiler techniques thatutilize polyhedral loop transformations to optimize the source codeduring compilation. The mechanisms of the illustrative embodimentsconvert a traditional program statement view of the source code into aprogram loop view of the source code such that each individual statementin the source code may be operated on rather than the program as awhole. Thereafter, the loops in the program loop view are optimizedusing code generation transformations that improve the control flowoverhead of the program without modifying the program order of thestatements in the program statement view of the program. As a result,after the optimizations, the resulting modified program loop view of theprogram may be converted back to a program statement view of the programfor further optimization.

FIG. 5 is an exemplary diagram illustrating a traditional orconventional polyhedral approach to source code optimization duringcompilation. The polyhedral loop optimization mechanisms are part of oneof many compiler phases. The input and output of the polyhedral loopoptimization mechanism 500 are given in a compiler internalrepresentation (IR) of statements, conditionals, and loops received froma compiler 505. As shown in FIG. 5, the polyhedral loop optimizationproceeds from left to right in FIG. 5 starting with a polyhedral scan bya polyhedral scan module 510 of the original program from the compiler'sIR into a polyhedral representation, referred to as the programstatement view 520. In this representation, each statement in the sourcecode is associated with a polyhedron describing its domain (how manytimes it iterates in each of its loop dimensions) as well as itsschedule (when it is executed with respect to all other statements). Theschedule may be represented as a structured matrix having threesub-matrices: (1) the Alpha matrix, which represents the speed at whichstatements are fired along a given time dimension; (2) the Beta matrix,which represents the sequential interleaving of statements along thedifferent loop depths; and (3) the Gamma matrix, which represents theconstant parametric shifting along each time dimension. See Girbal etal. “Semi-Automatic Composition of Loop Transformations for DeepParallelism and Memory Hierarchies, IJPP 2006, which is herebyincorporated by reference. The generation of a program statement viewusing a polyhedral representation is generally known in the art andthus, a detailed explanation of the mechanisms for representing aprogram in a program statement view using a polyhedral transformationwill not be provided herein.

In the program statement view of the program, a loop optimizer module530 is used to perform transformations on the program statement view tooptimize the code. Examples of transformations performed by the loopoptimizer module 530 include loop interchange, parallel wavefront, andstatement shifting loop transformations, discussed in more detailhereafter. The transformations performed by the loop optimizer module530 serve to modify the schedule of each individual statement in theprogram statement view to achieve better data parallelism and/or datalocality of the execution of the program. The transformations performedby the loop optimizer module 530 affect all runtime instances of a givenstatement. Thus, it is possible to skew the execution of one statementin a loop with respect to another, or to pull a statement out of oneloop and put it before/after a statement in another loop, for betterdata locality/parallelism.

The resulting transformed program schedule and its corresponding domainare provided to a polyhedral code generator 540 which operates on theentire program as represented by the modified IR generated by the loopoptimizer module 530, based on the program statement view 520 of theprogram output by the polyhedral scan module 510. The polyhedral codegenerator 540 generates an abstract syntax tree (AST) representation ofthe program based on the modified IR. Some limited optimizations 550-560may be applied to the entire program as represented by the AST. Theseoptimizations are limited in two ways. First they apply to all nodes inthe AST regardless of needs or benefits. Some known implementationsapply a transformation to all nodes skipping the top X levels of the ASTtree (e.g. X=2 skipping the root and the next level down but thenapplying the transformation to all the next levels below). Second, thelist of optimization used is fairly limited to aggressive if-hoisting(meaning removal of if-conditions at the expense of sometimeout-of-control code replication) and some modulo guard removal (meaningsimplification of complex modulo calculus present in bound computationor if-conditional computations).

Note also that code optimizations are very different from loopoptimizations in that loop optimizations typically change the structureof the computations by changing the order in which statements areexecuted with respect to each others and/or by adding/removing loopsaltogether. Code optimization, like the ones described here, however,typically do not transform the order in which statements are executedwith respect to each other but simply attempt to reduce overheadgenerated by a overly simplistic code generation scheme.

In essence, the module 540 is designed to generate valid code, possiblywith overhead due to extra bound computation, if conditional, modulocalculus in bounds and/or conditional computations. It is then theresponsibility of optimizations like 550, 560, and 570 to clean up someof the introduced inefficiencies as best as possible. The resultingoptimized AST is provided to a code emitter 570 which generates codefrom the AST in the compiler's internal representation (IR) by simplyconverting the internal AST and stripping it of its polyhedralinformation and generating an equivalent structure that is familiar andrecognized by the traditional compiler.

The polyhedral code generator 540, code optimizations 550-570, and codeemitter 580 operate as a monolithic block. Moreover, any, all, or anysubset of the optimizations 550-570 may be bypassed if desired, asrepresented by the dashed curved lines, such that the particularoptimizations bypassed are not applied to the AST.

Again, it is important to note that in the known mechanism shown in FIG.5, at the program statement view 520, optimizations are performed withregard to all runtime instances of a given statement in the code.Moreover, the code optimizations 550-560 are performed with respect tothe entire program. At no time are optimizations made possible withregard to individual instances of statements in a program or evensub-parts of a statement. The mechanisms of the illustrativeembodiments, as discussed hereafter, provide such optimizationabilities.

FIGS. 6A-6F are diagrams illustrating the program statement view andexamples of the loop optimizer 530 transformations that may be performedon the program statement view. FIG. 6A provides some general notationsfor explaining the program statement view and these transformations. Asshown in FIG. 6A, a statement S1 in source code 610 may be representedas an array-based inequality 620 defining the iteration domain of thestatement S1. That is, each statement control can be captured throughparameterized affine inequalities: Ax≧c where A is a n times m elementmatrix of integer numbers, x is a m element vector representing each ofthe iteration variables, and where c is a n element vector of integernumbers or symbolic parameters. A maximal set of such consecutivestatements is referred to as a static control part (SCoP) in thepolyhedral loop transformation literature. For each statement, an affinefunction θ(x)=Tx+d (where T is a n′ times m element matrix of integernumbers, x is a m element vector representing each of the iterationvariables, and where d is a n′ element vector of integer numbers orsymbolic parameters) assigns logical dates, e.g., time steps starting tozero and monotonically increasing, to iterations of Ax≧c.

As shown in FIG. 6B, the polyhedral scan module 510 extracts aniteration domain 640, access functions 650, and schedule 660 of eachstatement in the source code 630. The iteration domain 640 of astatement is a set of integer values taken by the multidimensionaliteration i. The iteration domain 640 may be defined as a set of linearinequalities, e.g., i≧0, M−i−1≧0, j≧0, N−j−1≧0 in FIG. 6B, forming aconvex polyhedron. The access functions 650 correspond to the polyhedralrepresentation of which specific memory location is accessed for a givenstatement. For example, in FIG. 6B, the second statement 632 iscontrolled by the index variables i and j for, respectively, theoutermost and the innermost loop. An access function for memoryreference “Z[i]” in statement 632 will indicate, to the internalrepresentation, which specific memory location will be written into whencomputing the data associated with that statement for a given instanceof i and j. The access function is a matrix with one row per dimensionof the array (Z[i] is a one dimensional array) and one column for eachof the index variables (i and j here), parameters (M and N here) plus aconstant integer. Thus the access function for Z[i] is [1 0 0 0 0] asshown in 652, as it is only a function of the index variable i.

For the “a[i][j]” reference, the access function 654 is a twodimensional array and, as a result, the access function 654 is a 2×5element matrix. The first row corresponds to the access function for thefirst dimension of the array A, solely a function of index variable ihere. The second row corresponds to the access function for the seconddimension of the array A, solely a function of index variable j here.For Y[j], the access function 656 is again a one dimensional array thatis solely a function of the index variable j.

The schedule is a linear function assigned to a statement that preciselydetermines a logical timestamp for the execution of each instance of astatement. These logical timestamps express a partial order betweeninstances of statements. As with the domain 640 and the access functions650, the schedule 660 is a linear function of the domain iterators,e.g., i and j, and global parameters, M and N. The extraction ofiteration domain 640, access functions 650, and schedule 660 isgenerally known in the art and thus, a more detailed explanation is notprovided herein.

Having extracted the iteration domain 640, access functions 650, andschedule 660, to generate a program statement view 520 of the sourcecode, the loop optimizer 530 may perform transformations on the scheduleto achieve better parallelism/locality. FIGS. 6C-6F illustrate varioustypes of transformations that may be performed on the program statementview 520.

In FIG. 6C, the original code 671 is scanned through the polyhedralrepresentation and a null-transformation is applied, depicted as element673 in FIG. 6C. Namely, the outer loop in the original code 671, i.e.the loop iterating over index i, is mapped to the first time dimensiont1 and the inner loop in the original code 671, i.e. the loop iteratingover index j, is mapped to the second time dimension t2. The resultingcode is shown in FIG. 6C as element 672. Note that in the statement S inthe resulting code 672, the original index i is set to the same value ast1, and the original index j is set to the same value as t2. Those ofordinary skill in the art will notice that the original code 671 and theresulting code 672 will execute the same statements exactly in the sameorder.

In FIG. 6D, the original code 681 is scanned through a polyhedralrepresentation and a loop interchange transformation 683 is applied.Namely, the outer loop in the original code 681, i.e. the loop iteratingover index i, is mapped to the second time dimension t2 and the innerloop in the original code 681, i.e. the loop iterating over index j, ismapped to the first time dimension t1. The resulting code is shown aselement 682 in FIG. 6D. Note that in the statement S of the resultingcode 682, the original index i is set to same value as t2, and theoriginal index j is set to the same value as t1. One of ordinary skillin the art will notice that the original code 681 executes thestatements in which, for a given value of i, all the values of j will bevisited before visiting the next value of i. However, in the resultingcode 682, the code executes the statements in a different order. Namely,for a given value of j, all the values of i will be visited beforevisiting the next value of j. This transformation is referred to as aninterchange of the loop i and j, precisely because of this change inordering.

In FIG. 6E, the original code 691 is scanned through the polyhedralrepresentation and a loop skewing and parallelization transformation 693is applied. In this transformation 693, the two i and j indices areprojected to a single time dimension t1=i+j. Thus, at the logical timedate t1=3, the original iteration (i=1,j=2) and (i-2, j=1) are logicallyexecuted. This is illustrated by the DOALL loop in the resulting code692. A DOALL loop is a parallel execution of a loop, where logically allthe iterations can be executed in parallel.

In FIG. 6F, the original code 694 is scanned through the polyhedralrepresentation and a loop shift transformation 697 is applied where thetwo matrices T1 and T2 are unchanged but where the vector D2 is (1, 0)instead of the original default value of (0, 0). This means that thesecond statement S2 will start executing one full outer-loop iterationstep after the first statement S1. The resulting code is shown aselement 695. Note that in the first portion 698, the statement S1executes alone for the full t2=1 to 3 range of iterations, beforestatements S1 and S2 start to jointly operate in the portion 696. At theend of the execution of the doubly nested loop in portion 696, one fullouter-loop iteration step will remain to be computed for the secondstatement S2. This remaining outer-loop iteration step is computed inportion 699.

With reference again to FIG. 5, the optimized program statement view 520generated through operation of the loop optimizer mechanism 530 ismapped, by the polyhedral code generator 540 to a hierarchical set ofloop structures referred to as an abstract syntax tree (AST). Themapping is performed by using a Quillere's projection and decompositiontechnique, which is generally known in the art. See Quillere et al.,“Generation of Efficient Nested Loops From Polyhedra,” InternationalJournal of Parallel Programming, 28(5):469-498, October 2000. The ASTrepresents the imperative execution of the program statements in thesource code. More precisely, each intermediate node of the program inthe AST bears a polyhedron whose size is related to the depth d of thenode. Each such polyhedron defines the non-redundant set of constraintsneeded to scan all the points in the corresponding transformed loop ofdepth d. The nesting of these polyhedra is directly translated into thenesting of the resulting loop nest. The leaves of the tree represent thepolyhedral statements.

FIGS. 7A-7C illustrate a mapping using Quillere's projection anddecomposition technique. Given the code fragment shown in FIG. 7A, threestatements S1, S2, and S3 are present and the subject of the polyhedralloop transformation. A set of points 710 iterated by the threestatements is generated and the set of points 710 is separated intoconvex areas of uniform statement sets 712-718. The abstract syntax tree(AST) is formulated by projecting along each of the dimensions using theabove mentioned Quillere's projection and decomposition technique.Usually, the most straightforward way to generate the resulting AST isto apply the following simplified steps: 1) create the scatteringpolyhedron for each statement by extending the iteration domain with theequalities linking time iterations to domain iterations; 2) recursivelyproject the previous polyhedron on the outermost time dimensions todetermine the span of each statement along every transformed timedimension; 3) recursively perform the intersection, difference, andordering of the previously projected scattering polyhedra for allstatements to distribute their iterations along the new time loops; and4) recursively sort the disjoint union of polyhedra along each timedimension. For more detailed explanations of these steps, reference ismade to the work of Quiller'e et al. previously mentioned above.

The resulting AST is hierarchical, with the top node representing anoutermost loop. This node corresponds to a single interval parallel tothe i-axis after projecting away the j-dimension. Since, in the depictedexample, all 3 statements have the same interval i=1 . . . n in thisprojected one-dimensional space, all 3 statements belong to this singlenode. Thus, there are 4 nodes 720-750, one for each distinct area inFIG. 7B. A domain is associated with each node. Domains are shown nextto each node 720-750 in FIG. 7C.

It is important to note that nodes sharing a single parent are ordered.This order must represent a correct sequence with respect to theoriginal order in the original program, or at least, if the originalorder was modified by loop transformation, must not violate anydependence present in the original program.

As discussed above, minor optimizations may be made to the AST generatedthrough the operations above which are applied to the program as awhole. The resulting AST is then used to generate a compiler internalrepresentation (IR) and is provided back to the compiler.

Moreover, as discussed above, the polyhedron-based approach describedabove has some significant drawbacks in that (1) it may not alwaysgenerate optimal code; and (2) the transformations performed necessarilytouch all instances of a given statement, rather than individualinstances. This means that the code may suffer from sub-par scalarperformance, unnecessary code bloat, and parallelism may be difficult toexpress for statements that are partially parallel, i.e. a statementthat is parallel in all but a few boundary instances. Moreover, for datalocality enhancement, requiring that tiling must be performed on allinstances of a statement, including the rarely executed boundaryconditions, results in unnecessary code bloat as well as increased loopoverhead. Thus, it would be beneficial to have a mechanism for allowingoptimizations to be performed on individual instances of statements.

FIG. 8 is an exemplary block diagram of an advanced polyhedral looptransformation mechanism in accordance with one illustrative embodiment.As shown in FIG. 8, with the advanced polyhedral loop transformationmechanism 800, a compiler internal representation (IR) of statements,conditionals, and loops is provided from the compiler 805 to thepolyhedral scan module 810 which operates in much the same manner as theknown polyhedral scan module 510 in FIG. 5 to generate a programstatement view 820 of the source code. Loop optimizer module 830 mayapply various loop optimizations on the statements in the programstatement view 820 in much the same manner as the loop optimizer module530 in FIG. 5. The resulting optimized program statement view of thesource code is provided to the polyhedral code generator 840. This iswhere the mechanisms of the illustrative embodiments depart from theknown polyhedral loop transformation mechanisms and provide advancedoptimization mechanisms not previously known.

There are two main directions in which the mechanisms of theillustrative embodiments improve upon known compiler mechanisms. First,the mechanisms of the illustrative embodiments provide a re-entrancepath (shown as the arc passing through the polyhedral rescan module870). In order to make this re-entrance path workable in theillustrative embodiments, data about the way in which the polyhedralcode generation is performed, is maintained for use by the polyhedralrescan module 870 to convert the AST, or program loop view, 850 backinto a program statement view 820. This data may include, for example,the Alpha, Beta, and Gamma matrices for each of the statements in theAST 850 along with a remapping matrix that identifies how atransformation back to a program statement view from the AST, or programloop view, 850 may be performed.

In the second major direction of improvement, the mechanisms of theillustrative embodiment provide an improved manner by which codegeneration optimizations may be applied by the code generationoptimization/parallel detection module 860. These code generationoptimizations may be applied with greater flexibility than knownmechanisms since there is no fixed sequence of code generationoptimizations, there are a greater number of code generationoptimizations, and the code generation optimizations may be applied tospecific sub-trees of a given AST 850.

In addition to the improvements above, the mechanisms of theillustrative embodiments provide functionality for determining when toreunite statements, upon re-entrance, that were split by the polyhedralcode generator module 840. That is, when the polyhedral code generatormodule 840 operates on the program statement view 820, sometimes theQuillere projection discussed above may result in statements being splitinto multiple nodes of the resulting AST or program loop view 850. Forexample, in FIGS. 7A-7C, statement S1 appears in two of the leaf nodesof the resulting AST and S2 appears in four of the leaf nodes due tosuch splitting of statements.

Sometimes it is desirable to keep the statement separated when doingre-entrance and in other situations it is more desirable to reunite theseparated statement into a single statement in the resulting programstatement view of the re-entrance. Thus, in the polyhedral rescan module870, a determination may be made whether to keep the separated statementseparate or to reunite the separated statement. This will be describedin greater detail hereafter with regard to FIG. 10, for example. As willbe described later, it is desirable, for example, to keep a statementseparated in order to perform optimizations on the kernel only, whileother times, reuniting the statement is proper. This decision may bemade automatically by the polyhedral rescan module 870, or in responseto user commands, such as through directives/scripts, or the like. Thedetails of the various improvements provided by the illustrativeembodiments will be described in greater detail hereafter.

As shown in FIG. 8, the polyhedral code generator 840 of theillustrative embodiments converts the program statement view 820 of thesource code into a program loop view or AST 850. In this view of thesource code, each loop is associated with a set of statements thatiterates over the same number of iteration points as experienced at agiven depth level in the loop nest hierarchy. An example of the programstatement view 820 is the data gathered in FIG. 6B. An example of theprogram loop view or AST 850 is shown in FIG. 7C. The major differencebetween the program statement view 820 and the program loop view or AST850 is that in a program loop based representation, two or morestatements can be assigned to the same logical loop even though thestatements do not have exactly the same domain. For example, in FIG. 9,discussed hereafter, loop 1 and loop 2 can be fused even though thedomains do not strictly overlap. When generating the AST 850, each ofthe nodes (which correspond to a loop, but for the leaf nodes thatcorrespond to a statement) correspond to strictly one loop in which allthe statements inside have exactly the same sub-domain. This is why onestatement in the program statement view 820 may become many nodes in theprogram loop view or AST 850, e.g. statements in loop1 in FIG. 10,hereafter, become 3 statements and statements in loop2 also become 3statements.

Thus, in the program loop representation, an original statement in theprogram statement view 820 may be split among several loops in theprogram loop view 850. For example, if two statements S1 and S2 werefused into a single loop but S1 iterates from 0 to 100 whereas S2iterates only from 0 to 80, then the statement S1 may be split into twoloops in the program loop view 850, one from 0 to 80 when it co-executeswith S2 and one from 81 to 100 where it executes by itself.

That is, one type of loop optimization that is often performed, such asby loop optimizer module 830, in polyhedral loop transformations is“fusion.” Fusion attempts to improve data locality by fusing two loopsthat iterate over similar ranges into a single loop. FIG. 9 illustratesan example of a polyhedral loop transformation fusion operation. Asdiscussed above, with polyhedral loop transformations, statements arerepresented as polyhedrons representing the iteration space of the loopsassociated with the statement. Thus, for example, as shown in FIG. 9, afirst statement S1 is associated with two loops with bounds i=N, i<M,j=U, j<V. These bounds define a rectangle as illustrated in the firstgraph 910. Similarly, the second statement S2 is associated with twoloops whose bounds i=N′, i<M′, j=U′, j<V′, overlap the area of the firststatement S1. This second statement S2 is represented by the rectangleshown in the second graph 920.

Through fusion, the two statements are integrated with the result beingas shown in the graph 930. As shown in FIG. 9, the corresponding codeincludes loops 932-938 for representing the non-overlapping portions ofthe rectangles 910 and 920 and a loop 940 that represents the fused“kernel” of the statements S1 and S2 which represents the majority ofinstances of execution of the statements S1 and S2. Fusion thus,increases the speed of execution of the original code by causing themajority of area where the two statements S1 and S2 execute to beexecuted together. However, it can be seen from FIG. 9 that fusionrequires a large amount of replication of code.

With reference again to FIG. 5, in generating the program loop view 550from the loop optimized program statement view 520, the polyhedral codegenerator 540, separates the kernels, i.e. the common area or range ofiterations, of fused statements such that separate representations ofthe statements are provided. This is because, in the program loop viewor AST 550, output by the polyhedral code generator 540, each loop canonly contain a single set of instructions. However, since there is noreentrance in the mechanism shown in FIG. 5, the framework of FIG. 5cannot apply specific loop optimizations implemented in the loopoptimization module 530 only to the statements that are part of thekernel (e.g., the section of code fragment 940 in FIG. 9 where bothstatements S1 and S2 are being jointly executed). To the contrary, asmentioned above, in the mechanism of FIG. 5, loop optimizations can onlybe applied to the program as a whole.

In other words, the original representation 520 includes statements S1and S2 for their entire domain on which optimizations are being applied.The polyhedral code generator 540 discovers the actual loops that thefused statements S1 and S2 will execute in, but by then, i.e. after thepolyhedral code generator 540 has operated, it is too late to apply newloop optimizations defined in the loop optimization module 530 becausethe optimizations in 550, 560, and 570 operate on a AST representationthat is not amendable to optimizations such as in loop optimizationmodule 530. As a result, for example, it is not possible in theframework described in FIG. 5 to perform such loop optimizations as aunrolling optimization of the kernel using the powerful loopoptimization module 530 operating over the program statement view 520.

The mechanisms of the illustrative embodiments provide functionality forseparating out the kernels of fused loops such that separaterepresentations of statements are obtained upon which optimizations maybe performed. FIG. 10 illustrates the separation of fused loops intoseparate representations for each portion of the fused loops such thatthe representations are not shared. With reference again to FIG. 8, ingenerating the program loop view or AST 850 from the loop optimizedprogram statement view 820, the polyhedral code generator 840, separatesthe kernels of fused statements such that separate representations ofthe statements are provided. This is again because in the programstatement view or AST 850 representation output by the polyhedral codegenerator 840, each loop can only contain a single set of instructions.

However, with the mechanisms of the illustrative embodiments, thereentrance path (depicted as the arc from element 850 through element870 to element 820) may be activated. With this reentrance path, each ofthe instances of statement S1 and S2 may be considered as separate. Inother words, the domain of statement S1 may be split into the subdomains corresponding to the area/code fragment 1010, 1018, and 1014 inFIG. 10 and the domain of statement S2 may be split into the sub domainscorresponding to the area/code fragment 1012, 1018, and 1016. As aresult of S1 and S2 now not sharing a common representation, looptransformations may now be applied, e.g., by the loop optimizationmodule 830 in FIG. 8, on the separate representations. For example, theloop containing both instances of statements S1 and S2, e.g., thearea/code fragment corresponding to 1018 in FIG. 10, may be unrolledwithout impact on the other instances of statements S1 and S2, e.g., inthe areas/code fragments corresponding to area 1010, 1012, 1016, and1014.

As shown in FIG. 10, for a fusion of two statements S1 and S2, when thestatements are separated out, 5 different domains 1010-1018 andcorresponding schedules 1020-1028 are generated by extracting the kernelin the representation of the fused statements. This is done by providinga separate domain and schedule for each of the boundary portions1030-1036 of the fused statements where only one statement applies, anda separate domain and schedule for the kernel 1040 where both statementsapply.

As a result, the program loop view of the source code includes separaterepresentations for each statement, as well as the kernel, upon whichcode generation optimizations may be applied by the code generationoptimizer/parallel detection module 860. For example, code generationoptimizations such as simplification and unstretching, if hoisting,substitute modulo, loop unrolling, etc. may be applied to the programloop view to obtain lower control overhead of the code. The program loopview may then be rescanned and converted back to a program statementview via the reentrance path after having undergone code generationoptimizations by the. The result of the reentrance path is a programstatement view of the code generation optimized program loop view thatmay be operated upon to provide even further optimization through aniterative process.

The optimizations that may be performed on the program loop view of theprogram, i.e. the “code generation optimizations,” may be applied bycode generation optimization/parallel detection module 860 in FIG. 8 tothe program loop view 850 of the program. These code generationoptimizations are performed on the polyhedral abstract syntax tree(AST), or the program loop view, and generate a new polyhedral AST, i.e.a new program loop view 850 for re-entrance to the program statementview 820 and/or emission back to the compiler 805. The code generationoptimizations represent a set of transformations that are performed inan iterative, modular, and flexible manner to help generate the codewith the least impeding control overhead as possible. An importantproperty of the code generation optimizations is that they do not changethe program order in the original polyhedral AST of the program loopview. They may induce statement splitting or aggregation and may evenmodify domain and schedule components. However, they do so in atransparent manner ensuring the strict equivalence of the relativeorders induced by the new schedules for all instances of all statements.

When considering program correctness, it is straightforward to realizethat different scheduling functions may produce the exact sameexecution. Indeed, only the relative execution order of all instances ofstatements is required. Therefore, a simple transformation like theshifting of all the statements by the same amount does not change anyrelative order of any statement instance and is said to produceequivalent schedules. Equivalence is a relation between two programs Pand P′ with respective global schedules S_(ch) and S_(ch)′. When aschedule transformation is applied to P, the resulting program P′ bearsthe exact same statements. Thus, program schedule equivalence is impliedby program equivalence. This notion must be preserved by any codegeneration optimization or transformation performed by the codegeneration optimization/parallelism detection module 860 in FIG. 8.

With this requirement in mind, each code generation optimization ortransformation executed by the code generation optimization/parallelismdetection module 860 takes two arguments: (1) a list of nodes in theprogram loop view referred to by prefix vectors in the program loop viewof the program; and (2) a propagation mode that can be, but is notlimited to, “any” (all the nodes in the AST are visited), “prefix” (allthe children of the given node are visited), or “exact” (only thespecified node is visited). The list of nodes, i.e. the prefix vectorlist, is made up of prefix vectors for the nodes that are to beoptimized by the particular code generation optimization selected. Thenodes of the AST of the program loop view, e.g., the nodes 720-750 inFIG. 7C, may be characterized as a vector of numbers which indicate itspath from the root (top-most) node. This vector of numbers is referredto as the prefix vector for the node.

The list of nodes may be made up of a listing of such prefix vectors.The prefix vector list defines the scope of the code generationoptimization in that it indicates where the code generation optimizationis allowed to modify nodes. Traversals of this list of nodes may beperformed, for example, by a depth-first-search listing a parent beforeany of its children, a depth-first-search listing a parent after each ofits children, a depth-first-search listing leaves only, or the like.

A code generation optimization may be called by the mechanisms of theillustrative embodiments, such as by the code generationoptimization/parallelism detection module 860 in FIG. 8 eitherautomatically or in response to a user request for a particular codegeneration optimization, to operate on individual statement instances,and/or sub-statement instances, in the program loop view 850 using acall such as “CG_codegenopt(optName, P, preftype), where optName is thename of the code generation optimization that is to be applied, P is theprefix vector list that will serve as a basis for flagging nodes in theAST to which optimizations are to be applied, and preftype specifies theprefixes found in P are to be treated as exact filters or prefixfilters, i.e. “any,” “pref,” or “exact.” For example, the call“codegenopt(simplify, {{1}, {2,0}, {3,3,3}}, BMT_exact)” will try tosimplify exactly the nodes at the specified list of vectors in the ASTof the program loop view.

The types of code generation optimizations that may be applied to theAST of the program loop view are varied and evolving. A current listingof code generation optimizations includes, but is not limited to,simplify, simplify-unstretch, simplify-trivial-modulo-remapping,extract-kernel, if-hoist/if-hoist-gentle, if-hoist-brutal,substitute-modulo, and loop-unroll. The simplify code generationoptimization is a basic simplification under context, normally calledfrom inside the code generation optimization module. Thesimplify-unstretch code generation optimization is a more elaboratesimplification that also reverts any “domain stretching” phase thatprevents over-separation in the code generation optimization phase whennon-unimodular schedules are present. Thesimplify-trivial-modulo-remapping code generation optimization is abasic simplification plus explicit instantiation of equalitiespropagated to the leaves which results in either disproving orsimplifying modulo conditionals. This can be viewed as a constantpropagation for modulo guards that may also disprove some statementswhen the modulo guards cannot be met.

The extract-kernel code generation optimization computes and extracts afully unrollable kernel from a loop with complex bounds (min, max,floor, and ceiling). This usually results in 0+ prologues, 1 kernel and0+ prologues and may yield code bloat if not done carefully. Theif-host/if-hoist-gentle code generation optimization walks the childrenof the given node and finds conditions on the current loop's depth andhoists them. The if-hoist-brutal code generation optimization walks theleaf nodes, finds any condition on any depth smaller than the currentloop's depth and brutally hoists everything. The substitute-modulo codegeneration optimization simplifies modulos aggressively without takingcare of compatibility within different statements. When all statementsin a loop have the same modulo substitutions, this is a powerful tool toembed the modulos into the enclosing loops' bounds. The loop-unroll codegeneration optimization performs a full unroll of a loop with staticconstant bounds difference. This code generation optimization shouldusually be preceded by an extract-kernel and a if-hoist-gentle codegeneration optimization if the bounds are complex (min, max, floor,ceiling) otherwise many inner conditionals may be generated. These areonly examples of currently known code generation optimizations and notintended to be limiting in any way. Other code generation optimizationsmay be used in addition to, or replacement of, the listed codegeneration optimizations without departing from the spirit and scope ofthe present invention.

When applying the code generation optimizations using the codegeneration optimization/parallelism detection module 860 in FIG. 8,based on the prefix vector list and the propagation mode, a first passis performed on the program loop view, e.g., the AST of the program loopview, to flag the nodes that need to be processed. The reason why aseparate pass is used to mark the nodes is that someoptimizations/transformations may duplicate nodes while some others maydelete nodes, making the prefix vectors obsolete very quickly. Thus,prior to any code generation optimization/transformation beingperformed, the nodes that are to be processed are first flagged.

After having flagged the nodes to be “visited” by a code generationoptimization/transformation, a code generationoptimization/transformation application algorithm is executed by thecode generation optimization/parallelism detection module 860 in FIG. 8to thereby apply the called code generation optimization/transformation.FIG. 11 is an example of pseudocode of an algorithm for applying codegeneration optimizations/transformations. All code generationoptimizations/transformations share the same template implementationbased on visitors. Visitors are instantiated at 3 different points inthe algorithm. First, a visitor is used to perform an outermost scan ofthe nodes in the AST of the program loop view. Each code generationoptimization scans the nodes that have been marked by the filteringpass. For each marked node N, the code generation optimization appliesits core function which determines if the node's domain is modified andreturns the list of new domains to replace the obsolete ones. This listis sorted with respect to the current time dimension under the parentpolyhedral context with the same algorithm proposed by Quillere,referenced above.

The core function is the second point where an inner visitor isinstantiated. Each new domain in the list then generates a new node N′and its corresponding subtree, which is a copy of the subtree rooted atN and simplified in the context of N′. Once the new subtree list isattached in place of the original node N, the propagation function iscalled along each path to every new leaf. Such propagations areperformed by a third inner visitor that may void nodes in the newsubtrees which need to be removed recursively in a bottom-up order. Toavoid interfering with the outer visitor traversal, special care istaken. Therefore, the node removal function is implemented with aboundary node argument and is only allowed to delete descendents of thatnode. This guarantees that the outer application visitor and the innerpropagation visitor are always operating on non-conflicting regions ofthe AST.

Some of the above example code generation optimizations that may beimplemented using the mechanisms of the illustrative embodiments willnow be described in greater detail. It should be appreciated that whilespecific code generation optimizations are described herein, theillustrative embodiments are not limited to these code generationoptimizations and may operate to implement other code generationoptimizations in addition to, or in replacement of, one or more of theherein described code generation optimizations.

As mentioned above, one of the code generation optimizations that may beperformed by the code generation optimization mechanism of theillustrative embodiments is the conditional hoisting, or if-hoisting,code generation optimization. Conditional hoisting performs a controlledtradeoff between code size growth and spurious inner conditionalsremoval. The core function determines all spurious conditionals for amarked node and factorizes them.

Two application modes are possible when processing a node N of depth d.In the least aggressive mode, the visitor traverses all the children ofnode N. The visitor looks for conditionals directly expressed as afunction of (t_(i))_(iε[1,d]) and constants only. Such constraints donot concern the time iterators at depth d′>d and are thus, affine guardsthat can be hoisted. In the aggressive mode, the visitor traverses onlythe leaf nodes under node N and performs a polyhedron projection of eachseparate statements' domain on the vector space (t₁, . . . , t_(d), N).A subsequent simplification in the context of the parent node yields thenew conditionals.

In both modes, the non-redundant list of conditionals is maintained.Eventually, the difference is computed with the reference node's domain,yielding the core list of conditionals representing all possible casedistinctions. In each of these cases, a single condition holds. As anapplication, consider the following variants with the differentconditional hoisting modes as shown in FIGS. 12A-12C. FIG. 12Arepresents the original code. FIG. 12B represents the same code with agentle, or least aggressive, mode of conditional hoisting having beenperformed. FIG. 12C represents the same code with an aggressive mode ofconditional hoisting having been applied.

As one can see, FIG. 12A includes several conditional statements, i.e.the three “if” clauses in FIG. 12A, that will execute at each iterationof the outermost t1 loop, even though the condition associated with theconditional statement will evaluate to true for only one or twoiterations of the entire t1 loop iteration. This represents asignificant overhead, which can be removed the conditional hoistingoptimization. While in general the aggressive technique can get rid ofmore conditional statements at the cost of more replication, one can seethat in this case, the gentle approach (result shown in FIG. 12B) wassufficient to remove all conditionals. The aggressive technique (resultsshown in FIG. 12C) also resulted in all of the conditionals beingremoved, but resulted in more code than the gentle approach.

In most cases, the gentle mode is enough and yields potentially muchsmaller code. In special cases, however, the more aggressive, or“brutal,” mode is needed to perform more advanced conditional hoisting,such as in the case of loop unrolling after tiling. To see that programequivalence is preserved is rather straightforward. Conditional hoistingis actually a domain splitting on the time dimensions. Suppose I and I′are ordered instances of two statements that execute respectively attime t and t′ such that t<t′. Two cases arise: (1) both instances belongto the same new split domain after transformation and their order isenforced by the schedule; and (2) each instance belongs to a differentsub-domain, in which case the relative order is enforced by thedisjunction and the subsequent ordering. Lastly, since the difference iscomputed with the reference node's domain, no iteration is lost.

Another code generation optimization/transformation that may be appliedto the program loop view 850 in FIG. 8 by the code generationoptimization/parallelism detection module 860 is the kernel extractioncode generation optimization/transformation. When loopoptimizations/transformations such as skewing or strip-mining areapplied, the generated loops exhibit complex bounds which can degradeperformance or prevent further desired loop unrolling. Kernel extractionis a transformation that enforces the separation of such complex boundsin different versions of the loops. This transformation has threeversions: (1) the unrollable kernel extraction detects pairs oflower/upper bounds that exhibit a static constant difference; (2) thelower bounds kernel extraction creates a list of conditionals whereevery lower bound is minimal exactly once. If at depth d, the scattered,separated domain exhibits t_(d)≧(l_(i))_(iε[l,k]), the resultingconditionals are a list of k elements such thatt_(d)≧(l_(i))_(iε[l,k]-{j})>l_(j); and (3) the upper bounds kernelextraction creates the same list of conditionals with the upper bounds,i.e. t_(d)≧(u_(i))_(iε[l,k])=>t_(d)≧(u_(i))_(iε[l,k]-{j})>u_(j).

The result of a simple example is shown in FIGS. 13A-13C. FIG. 13Arepresents the original code of the depicted example. FIG. 13Billustrates skewing of the original code along a first dimension. FIG.13C illustrates a result of the kernel extraction code generationoptimization/transformation. In the kernel extraction code generationoptimization/transformation, the program equivalence property isobtained the same way as in the conditional hoisting code generationoptimization/transformation. Kernel extraction may be followed by asubsequent loop unrolling pass. This transformation (loop-unroll)performs full unrolling of the iterations of a given node. Given itsnatural code expansion characteristics, is applied at the innermostdepths.

As shown in the example of FIG. 13A, there is a simple statement insidea doubly nested loop. FIG. 13B shows this same statement after loopskewing optimization was applied. Loop skewing is most often used toparallelize code by modifying the order in which statements are executedso that the dependencies present in the original code do not hinderparallelization of the inner loop(s). The salient observation is that inFIG. 13B, there are minimum (min) and maximum (max) functions in theloop bound computation of the innermost loops. These min/max functionswere introduced by the loop skewing optimization, and their cost maysignificantly impact on the execution time of the loop. Using the kernelextraction of the illustrative embodiments, the domain of execution ofthe outer loop may be split so that the min(X, Y) function always takesits X value in one of the copy of the outermost loop, or Y value in thesecond copy of the outermost loop, in FIG. 13C. Because of thisproperty, the min function may be safely removed from the code as it isstatically known that the smallest number will come from the X value inthe first instance of the loop and the Y value in the second instance ofthe loop.

In addition to code generation optimizations, the code generationoptimization/parallelism detection module 860 in FIG. 8 further detectsparallelism in the program loop view 850. When specifying parallelism atthe schedule level only, there is a semantic gap between the syntacticloop model and the schedules that are expressed with the polyhedralmodel. One such example, is given in FIGS. 14A-14C for 2 statements withthe same domain Dom={i in [1,N]}, with only the A and Beta parts shown.A and Beta are two components of the schedule associated with each ofthe statements. The schedule essentially associates a time stamp, e.g.,date, time, etc., with each instance of the statements. These timestamps indicate which of the instances of a statement comes first in theexecution of the code. Having a smaller time stamp number means thatthat instance of a statement comes prior to another instance that has ahigher time stamp number. The A matrix indicates how each of theiterations surrounding a statement are taken into account to computethat statement's time stamp. The Beta part indicates the order in whicha statement is to be found in the code. For example, a Beta of [0, 0]associated with statement S1 in FIG. 14A states that S1 is the firstloop and is the first statement inside that first loop.

Suppose that the target version shown in FIG. 14C is to be generated andthe dependencies between statement S1 and S2 allow it to be generated.However, if parallelism is to be expressed in the schedule directly, thecode in FIG. 14B is obtained where the parallel loops undergo a fissionoptimization. In other words, to express parallelism in the way proposedin FIG. 14A, a loop fission operation, i.e. statements inside a singleloop nest are separated into two or more loops each containing a subsetof the statements inside the original loop, is applied. This loopfission will have significant impact on the performance of the code.

On the other hand, enforcing the fusion of the loops yields the code inFIG. 14B where only the body of the loops is parallel. The parallelfused version requires the schedule to specify the same arbitrary orderon the outermost time iterator for the two statements while stillenforcing sequentiality between S1 and S2 at the loop independent level.Eventually, the constraints borne by the syntactical parallel versionare not expressible with a polyhedral schedule only, as shown by the“undef” labels inside of the A and beta representation in FIG. 14C,which represent the desired code for which the above scheme to expressparallelism within the polyhedral A and Beta scheduling matrices cannotbe used.

This expressivity issue is alleviated by the illustrative embodiments bymeans of a code generation optimization/transformation to detectparallelism. When it is applied to a node N of depth d, it creates alist of all statement leaves with their restricted domains afterseparation. This list is used to filter the dependence graph and tocheck if node N defines a loop which does not bear any dependence. Eachdependence is intersected with the current schedule of its source andtarget statements but also with their restricted domains. If theresulting polyhedron is not empty, the algorithm stops when aparallelism preventing dependence on depth d is found. On the otherhand, if all resulting dependences are empty, the loop is markedparallel and an OpenMP directive along with the shared and privatevariables information are generated. OpenMP used here is an exemplarycompiler and runtime support system that enable parallelism to beexpressed. OpenMP uses directives (generated either by the applicationuser and/or the compiler) that state which loop/region can safely beexecuted in parallel. OpenMP is used herein as only an example and isnot limiting to the mechanisms of the illustrative embodiments in anyway. To the contrary, in one illustrative embodiment, OpenMP is onlyused as one way to convey parallelism information to the remainder ofthe compiler/runtime system of the illustrative embodiment. Any otherparallel compiler/runtime system may be used without departing from thespirit and scope of the illustrative embodiments.

All this processing is performed by the core function of the codegeneration optimization/parallelism detection engine 860 in FIG. 8 whichnever modifies the constraints on the domain of node N, but rather setsa parallel bit to 1 in the internal representation associated with theloop. When it becomes time to emit the code, e.g., from emit module 880in FIG. 8, a parallel bit will be read to determine, for each loop,whether this loop is parallel or not. Upon a determination that the loopis parallel, the emit module 880 will generate the appropriate constructto inform the rest of the compiler/runtime system that this loop is aparallel loop. In one illustrative embodiment where OpenMP is used, thisconsists of emitting a pragma directive just prior to the loop.

Returning again to FIG. 8, as shown, the result of the code generationoptimizations and parallelism detection is a modified program loop view850 that is then either output to the compiler 805 or sent along are-entrance path to the polyhedral rescan module 870 for conversion backinto a program statement view 820 for further optimization.Determination on whether to go along the re-entrance path or not dependson various factors. First, it may be desirable to transform the code tothe program loop view 850 representation before completing alloptimizations in the program statement view 820 representation in orderto gather some knowledge about the code. For example it may be desirableto use the program loop view 850 to determine which loops are parallel,to see if kernels need to be extracted, to evaluate the complexity ofthe current code, and/or any other qualitative information that may begathered from the program loop view 850 representation. Once thisinformation is gathered, it is desirable to go back to the programstatement view 820 representation to exploit this additional knowledgefor further optimization of the code upon determination, based on thisadditional knowledge, that particular optimizations are advantageous.

Second, it may be desirable to apply all optimizations in the programstatement view 820 representation at once. In this framework, some loopoptimizations from the loop optimization module 830 may be applied andthen the program statement view 820 representation may be converted tothe program loop view or AST 850 representation. Specific codeoptimizations may be applied by the code generationoptimization/parallel detection module 860, such as kernel extractionand/or other code generation optimizations, and then the re-entrancepath may be traversed to go back to the program statement view 820.Further optimizations of specific aspects of the program loop view orAST 850 representations (after being modified by the code generationoptimizations) may then be performed. Both approaches above are notexclusive and may be jointly applied or applied repetitively in somealternating fashion.

With regard to the re-entrance path, the modified program loop view 850is parsed by the polyhedral rescan module 870 and data structuresexpected in the program statement view 820 are recreated from themodified program loop view 850. In this way, iterative calls to the loopoptimizer module 830 and the code generation optimization/parallelismdetection module 860 may be performed successively until a desired levelof optimization is achieved at which time the optimized code may beoutput back to the compiler 805. This is contrary to known mechanisms inwhich a single pass of the loop optimizer module 530 in FIG. 5 isperformed with some minor optimizations being performed on the entireprogram thereafter just prior to the emitting of the code back to thecompiler. No successive iterations are possible in known mechanisms.

In order to perform successive (iterative) calls to the optimizingframework comprising the loop optimizer module 830 and the codegeneration optimization/parallelism detection module 860, the output ofa given polyhedral optimization must be fed to the next phase withoutdisrupting the properties of the optimization found so far. Inparticular, if no further optimization is performed in the latter phase,one expects the result to exhibit the same properties, i.e. parallelism,memory locality, code size, control flow overhead, etc., as have beenobserved in the previous phase. That is, for example, the output of thecode generation optimization/parallelism detection module 860 shouldhave the same properties as the input to the code generationoptimization/parallelism detection module 860. In other words, there-entrance process must be stable by imposing the followingconstraints: (1) the code size must not increase; (2) the amount andgranularity of parallelism must not be modified; and (3) the relativeexecution order of all statements in the program must be preserved.Memory, or data, locality and reuse are strongly tied to the schedulingof the program and thus, no particular concern occurs with respect tothese features. On the other hand, code size and control flow overheadare very dependent on the code generation optimizations and theaggressiveness of the transformations, such as conditional hoisting ormodulo guard removal. Furthermore, when parallelism is directlyexpressed in the schedule, such as via the parallelism detectionmechanisms of the code generation optimization/parallelism detectionmodule 860, it may be hard to exploit properly at the syntax tree leveland even harder to reparse properly.

In practice, the mechanisms of the illustrative embodiments applytransformations that will change the representations 820 and 850.However, from an implementation perspective, even if no transformationsare applied, the quality of the representation is not degraded by thereentrance path. In other words, if the reentrance path is followed toapply a specific sequence of loop and code generation optimizations,which will result in a faster running code, but in the process degradethe representation which happens to slow the resulting code, then suchdegradation must be weighed against the benefit (better optimization).However, by practically ensuring that there is no degradation ofrepresentation while exercising the re-entrance path, as in themechanisms of the illustrative embodiments, the cost of implementing themechanisms of the illustrative embodiments with regard to codeperformance is approximately zero. Thus, the re-entrance path of theillustrative embodiments should always be exercised if thecompiler/application writer can determine a beneficial loop/codegeneration optimization sequence.

With the mechanisms of the illustrative embodiments, the polyhedralrescan module 870 performs program regeneration in order to generate theprogram statement view 820 from the program loop view 850. Programregeneration involves transforming the modified or new AST of theprogram loop view 850 into a stable program with respect to codegeneration. In order to generate a stable program, each statement in thenew stable program needs to have its own domain that does not overlapwith other instances of the same original statement. Each schedule mustenforce the same relative order with respect to all other instances ofany other statement. Furthermore, subsequent call to a separationalgorithm in the program statement view optimizations of the compilershould result in the same AST as originally presented to the codegeneration transformations. In order to achieve all of these goals,schedule reconstruction, domain reconstruction, and domain stretchingtransformations are performed to generate a new stable program. This newstable program may be fed back to the program statement view stage ofthe compiler for further optimizations by the program statement viewoptimizations.

As discussed above, the loop optimizer 830 applies polyhedraltransformations to the program statement view 820 of the program orsource code. The code generation optimizations, on the other hand, havethe sole purpose of reshaping the AST of the program loop view 850 forlower control flow overhead. These latter transformations do not modifythe program semantics in any way although they may result in differentequivalent schedules after regeneration via the re-entrance path. Assumethat the original program source code is referred to as P, the AST ofthe program loop view 850 is AST^(P), the code generation optimizationsused to generate the AST^(P) are denoted P_(CG), and the stable programgenerated from the AST^(P) using regeneration is P′. Using thisnotation, the transition graph for the iterative polyhedral looptransformation optimizations of the illustrative embodiments is shown inFIG. 15 where the goal, which is achieved by the illustrativeembodiments, is to ensure AST^(P)≡AST^(P′) in order to build a stable,reentrant and iterative framework that does not rely on any other partof the global compilation chain to iterate.

Consider a simple code fragment such as shown in FIGS. 16A-16C, withstatements S1, S2, and S3 covering the iteration points depicted in thegraphs below the code fragments. Considering the code in FIG. 16A, atypical representation of this program generated by the loop optimizermodule 830 is shown in FIG. 16B. Polyhedral code generator algorithms ofthe code generation optimization/parallelism detection module 860isolate the i==N data point from the others. After one or moreiterations of the loop optimizer module 830 and the code generationoptimization/parallelism detection module 860 using the optimizationsdescribed above, and without imposing the stability requirementsdiscussed herein, the code shown in FIG. 16C is obtained whereadditional data points have been isolated.

FIGS. 16A-16C illustrate the large code growth that may occur as abyproduct of successive polyhedral rescan operations by the polyhedralrescan module 870 and the successive operation of the code generationoptimization/parallelism detection module 860. This code growth willobviously impact the quality of the final code. In addition, by lookingcarefully at FIG. 16C, one notices that all the conditionals havemigrated from inside the loops to the top level (outside of any loops).This is a hard to reverse process that may prevent other optimizationsfrom being performed.

This code bloat and conditional migration occurs because of thefollowing reasons. Each time that the code goes through a polyhedralregeneration operation, and the statements are split, the subsequentpolyhedral code generation operation by the polyhedral code generator840 has less flexibility to combine the same original statements intoconvex areas with uniform sets of statements within itself. For example,in FIG. 16B, all the statements are under a unique “for i” loop becausethere are instances of S1/S2/S3 in the full i=1 . . . n range. Considerwhat happens to S1 the next time around. The original S1 has been splitinto 3 distinct S1.1, S1.2, and S1.3 sub-statements with, respectively,ranges for i=1 . . . n−2, i=1 . . . n−1, and i=n. These distinct rangeswill result in a top-level conditional with the resulting replicationseen in FIG. 16C. Thus, what is needed is a way to control thisreplication in order to prevent highly optimized code with poor singlethread performance due to instability conditions that leads to highlyduplicated code with a high degree of redundant replication and controloverheads.

This goal is achieved by the mechanisms of the illustrative embodimentsby recombining instances of statements prior to the polyhedral rescanoperation being performed so as to prevent the code growth shown in FIG.16C. These mechanisms are heuristically driven in that none of theoperations discussed hereafter are necessary but, if followed, the codegrowth for the particular statement operated will be prevented.

In order to perform this recombining of instances of a statement, anoperation is performed, such as by the polyhedral rescan module 870, onthe new AST generated by the code generation optimization/parallelismdetection module 860. As discussed above, the AST is an encodedhierarchical ordered graph where each inner node corresponds to aniteration domain at a given depth in the loop nest structure. Each leafnode has also a list of statements that are enclosed by the loop nest.For a given node N at depth d in the AST, the node is associated with adomain D^(N), which is a polyhedral representation of the domainassociated with the enclosed statements, and projected to reflect thedepth d of the node in the AST.

The requirements imposed by stability under the separation algorithm areless straightforward. Consider a node N of depth d in AST^(P). If itsscattering domain D^(N) projected on depths 1 . . . d-1 and simplifiedunder the parent domain is not the universe domain, it means node Nholds constraints that can be hoisted. A hoistable condition is aconstraint at depth j appearing in a polyhedron of depth k in the ASTsuch that j<k (i.e. a constraint in which the time dimension k does notappear in the constraint). Recall that the time t is represented by avector of time elements, with a lexicographical interpretation of thetimes. In the above statement, it is stated that a constraint in thetime dimension k does not appear if the k's position in the vector(starting from the left) is null. If such constraints were to appear inthe regenerated program, they would trigger the same separation behaviorfrom Quillere's algorithm as shown in FIG. 16A-16C. In turn, this wouldresult in the code bloat as shown in FIG. 16C. Therefore, in order toperform a stable polyhedral rescan operation to generate the programstatement view 820 from the newly optimized program loop view 850, thepolyhedral rescan operation must not specialize a statement'srepresentation past any node containing such a hoistable condition.

Thus, the mechanisms of the illustrative embodiments use the followingthree phase operation to ensure stability of the program code beingreturned to the program statement view 820. A first pass on the AST^(P)is used to detect the nodes containing hoistable conditionals bytraversing the tree of the AST^(P) in a depth-first search traversalorder (i.e. visiting/processing each parent node before each of its ownchildren. A parent, or father, node F is then marked as a boundary nodefor re-entrance if one or more of its direct children are detected ashaving one or more hoistable conditionals. Then, for each such boundarynode of a given depth d, all the instances of a given statement S′ areidentified and a single compound statement S in P′ is generated torepresent them. The set of instances of S under parent node F is denoted{S_(inst) ^(F)} where inst implicity denotes an enumeration of thedifferent instances of the given statement S under F. The new domain forthe compound statement is set as D^(S′)=union over all instances inst(⊥dom iters (D_(inst) ^(SinstF)).

In other words, the new domain associated with a given statement S isformed as follows. From node F, each of the leaf nodes (nodes withoutchildren) for which F is a (direct or indirect) parent is searched. Theunion of the domain associated with statement S at each of these leafnodes is generated. This union of domain defines the final domainassociated with statement S. The tradeoff with the above solution isthat statements in P′ do not correspond to the leaves of AST^(P). Thismeans that when the rescan process of the polyhedral rescan module 870is complete, and the program loop view 850 has been successfullytranslated back into the program statement view 820, each part of thestatements associated with each of the leaves under node F we will notbe able to optimized separately as they will have been grouped togetheras a single statement in order to avoid the problem associated with thehoistable condition. However, the new AST^(P′) resulting fromapplication of the code generation optimizations is guaranteed to be thesame syntax tree as the original AST^(P). This means that by doing suchgrouping of statements under node F, the hoistable condition problem hasbeen avoided and thus, the overall quality of the generated code has notbeen degraded by a cycle through elements 840 and 870.

Returning again to FIG. 8, as discussed above, after iterating theoptimizations performed by the loop optimizer 830 and the codegeneration optimization/parallelism detection module 860 via there-entrance path comprising the polyhedral rescan module 870 to achievea desired level of optimization, the resulting optimized code must beemitted, by the code emitter 880, to the compiler 805.

Determination on whether to go along the re-entrance path or not dependson various factors. First, it may be desirable to transform the code tothe program loop view 850 representation before completing alloptimizations in the program statement view 820 representation in orderto gather some knowledge about the code. For example it may be desirableto use the program loop view 850 to determine which loops are parallel,to see if kernels need to be extracted, to evaluate the complexity ofthe current code, and/or any other qualitative information that may begathered from the program loop view 850 representation. Once thisinformation is gathered, it is desirable to go back to the programstatement view 820 representation to exploit this additional knowledgefor further optimization of the code upon determination, based on thisadditional knowledge, that particular optimizations are advantageous.

Second, it may be desirable to apply all optimizations in the programstatement view 820 representation at once. In this framework, some loopoptimizations from the loop optimization module 830 may be applied andthen the program statement view 820 representation may be converted tothe program loop view or AST 850 representation. Specific codeoptimizations may be applied by the code generationoptimization/parallel detection module 860, such as kernel extractionand/or other code generation optimizations, and then the re-entrancepath may be traversed to go back to the program statement view 820.Further optimizations of specific aspects of the program loop view orAST 850 representations (after being modified by the code generationoptimizations) may then be performed. Both approaches above are notexclusive and may be jointly applied or applied repetitively in somealternating fashion.

It is important that the code that is emitted back to the compiler 805be of good quality even in the presence of highly optimized looptransformations, such as those of the illustrative embodiments, used fordata locality and parallelism where statements are executed at“different speed” from the original program.

FIGS. 17A-17C illustrate an example of code optimization where twostatements have had their speed accelerated by a factor of 3. FIG. 17Ais an example of the original code having a complex schedule. FIG. 17Bis an example of the original code after optimization and regenerationfor emitting back to the compiler. As can be seen from FIG. 17B,obviously something very wrong occurred as the code size has beensignificantly increased. Thus, significant code bloat is again foundwith typical optimizations.

With the illustrative embodiments, to avoid such code bloat, a domainstretching operation is performed to augment the code generationoptimization/parallelism detection operations that transform the programstatement view 820 into the program loop view 850. This operationessentially normalizes the domains associated with each statement bystretching them to their largest possible values without adding anyexecution points, which would otherwise change the semantics of theprogram. As a result of this optimization, which may be typicallyimplemented in the code generation optimization/parallelism detectionmodule 860 for example, high quality output code may be generated whileenabling a path in which a statement can be still meaningfully splitinto distinct sub-statements as previously described above. As discussedabove, these sub-statements may then be optimized as if they wereoriginal statements in the original program, namely the full range ofoptimizations such as loop fusion, loop splitting, loop skewing, looptiling, (non) unimodular loop transformations, and the like, may beapplied to these sub-statements as well.

As discussed above, the schedule of loops in a program may berepresented as a structured matrix having three sub-matrices: (1) theAlpha matrix, which represents the speed at which statements are firedalong a given time dimension; (2) the Beta matrix, which represents thesequential interleaving of statements along the different loop depths;and (3) the Gamma matrix, which represents the constant parametricshifting along each time dimension. The values of the Beta matrix willdiffer for each instance of an original statement S. The values of thisBeta matrix may be read from the inner data representation of the AST ineither the program statement view 820 or the program loop view 850.

When the loop optimizer 830 accelerates a statement with respect toanother, this yields a matrix Alpha with strides greater than 1 alongwith constant shiftings, and additional stability interplays occur withthe Quillere separation algorithm. For example, as shown in FIGS.17A-17B, both S1 and S2 are slowed by a factor 3 on a first timedimension and statement S2 is shifted by 1.

When considering the Alpha matrix, or A for short, transformations withstride greater than 1 along with shifting, the domains in thetransformed space become very unfriendly for re-entrance. For example,consider the simplified schedules in FIGS. 18A-18F. Initially,scattering domains are constructed in the time (i.e. transformed) spaceby applying the schedule function to the iteration domain for eachstatement in the program. This step actually expands the size of thedomain by a factor 3 producing the time bounds observed in FIG. 18B. Theseparation phase proceeds and yields the code obtained from the codegeneration optimization/parallelism detection module 860 as shown inFIG. 18C. Now, when the program P′ is regenerated in FIG. 18D, the newiteration domains are obtained by shrinking back the separated timedomains into the original space by a factor 3. The new expansion phaseperformed when reconstructing the new scatter domains in FIG. 18Ereturns different scattering domains that will be split further and makethe code size grow as in FIG. 18F. It is also important to notice howthe loop bounds on the first and last loops change between FIGS. 18C and18F when using re-entrance and going back and forth from time space tooriginal space. Actually, if no special care is taken, this process isrecurrent at each regeneration attempt and stability will never bereached in the context of such Alpha matrix schedules.

Thus, the mechanisms of the illustrative embodiments define a newtransformation, the scatter domain stretching transformation, to applyon domain constraints at scattering construction time. For eachstatement S the following operations are performed. First, the loopdepth Ds associated with statement S is determined. Then the HermiteNormal Form (Hnf) matrix is calculated from the Alpha scheduling matrix.The Hermite Normal Form matrix is constructed using a standard matrixtransformation (or linear algebra) that separates a given matrix X intoa product of two matrices Y * Z, where Y is a matrix in Hermite NormalForm and Z is a unimodular matrix. The Hermite Normal Form Y matrix is anon-negative, non-singular, lower triangle matrix such that for each rowi, the maximal element is Y_(i,i) (i.e. the diagonal element is largerthan any others on that row). A unimodular matrix is a rectangle matrixwhose determinant is either plus or minus one.

The scattering matrix Theta is computed using Alpha, Beta, Gammamatrices, and the domain of the statement S. For each time dimension Td(from 1 to Ds) the following operations are performed. The stride factoris computed as Sf=Hnf[Td, Td]. Namely the stride factor is the diagonalelement at row/column number Td in the Hermite Normal Form matrix. Upona determination that the stride factor Sf>1 then a determination is madeas to whether this stride factor Sf divides every component (i.e. timedomain, and parametric dimensions) in the scattering matrix for everyrow that contains a non-null Td entry.

If this check succeeds, then proceed as follows for each domainconstraints Cd that include Td. If Cd is determined to be a lower boundconstraint of the form “f(time, parameters)>=const”, then const isreplaced by floor((const-1)/Sf) * Sf+1 in the original domain matrix.Alternatively, if Cd is determined to be an upper bound constraint ofthe form “f(time, parameters)<=const”, then const is replaced byfloor((const+1)/Sf)*Sf−1 in the original domain matrix.

Once the above algorithm runs its course, the following post-processingis performed. The scattering matrix Theta is recalculated using Alpha,Beta, and Gamma matrices, and the modified domain. The resulting newscattering matrix is then void of the stretching constraint issue.

Note that the above example is only one exemplary way to process thetime constraints, as they are alternative ways to derive some of thecoefficients and/or other values that the constraints can be normalizedto. Those of ordinary skill in the art will readily understand, in viewof the present description, the manner by which the mechanisms of theillustrative embodiment may be modified for other implementations inwhich the coefficients and other values are represented differently. Thepresent invention is not limited to the particular illustrativeembodiments set forth above.

This transformation has the effect of stretching each constraint,encompassing into the domain every integer point of the time space thatis strictly non integrate in the original space. It providesnormalization for the scatter domains while guaranteeing that no newpoint is added to the original space. It further keeps the exact samenumber of executed instances for each statement while maximizing theoverlapping of time domains.

The scatter domain with stretching transformation of the illustrativeembodiments receives, as input, the Alpha, Beta, and Gamma matrices fora given statement as well as the domain for the statement. The scatterdomain with stretching transformation outputs a modified scatteringmatrix Theta′. An example of pseudocode for implementing a scatterdomain with stretching transformation in accordance with oneillustrative embodiment is provided as follows:

Determine the loop depth Ds associated with statement S; Compute the Hnf(Hermite Normal Form) matrix from the alpha matrix; Compute thescattering matrix Theta using Alpha, Beta, Gamma, and Domain for eachtime dimension Td (from 1 to Ds) stride factor Sf = Hnf[Td, Td] (thediagonal element at row/column number Td in the Hermite Normal Formmatrix); if stride factor Sf> 1 then check if this stride factor Sfdivides every component (i.e. time domain, and parametric dimensions) inthe scattering matrix for every row that contain a non-null Td entry; ifthis check succeeds, then for each domain constraint Cd that includesTd: if it is determined that Cd is a lower bound constraint of the form“f(time, parameters) >= const”, replace const by floor( (const−1) /Sf) * Sf+1 in the origina domain matrix; if it is determined that Cd isan upper bound constraint of the form “f(time, parameters) <= const”,replace const by floor((const+1) / Sf) * Sf−1 in the original domainmatrix; Recompute the scattering matrix Theta using Alpha, Beta, Gamma,and the modified domain.

In the above pseudocode, the Hermite Normal Form matrix is a matrixobtained from using the known Hermite Normal Form decomposition methodbut which is restricted to the case of a single transformation, or atbest to harshly constrained multiple transformations. The Hermite NormalForm matrix may be defined as follows: Given an integer matrix H of sizem×n and full rank, H is in Hermite Normal Form if and only if H=[B 0]where B is a non-negative, non-singular lower triangular matrix suchthat for each row I, the unique maximal element is b_(i,i)(i.e. Vj<i,b_(i,j)<b_(i,i)). Moreover, in the above pseudocode, the generation ofthe scattering matrix Theta from the Alpha, Beta, and Gamma matrices,and the domain, is generally known in the art.

FIGS. 19A-19B illustrate the scattering domains for S1 and S2 andresulting stable AST^(P′) obtained using the scatter domain withstretching transformation of the illustrative embodiments. Theoverlapping portion of the scattering domains is much friendlier tore-entrance stability but will still generate a cut for statement S2 and3N+3≦t1≦3N+4. However, this cut is actually non-integral in the originaldimension and it will indeed be removed from the resulting program loopview 850, i.e. AST^(P′). While domain stretching is described as atransformation for re-entrance, it also provides very efficientreduction in the number of separations performed by the separation phasebecause it helps in avoiding spurious border cuts.

FIGS. 20A-20C illustrate an example of domain stretching underre-entrance in accordance with one illustrative embodiment. This exampleconsiders the schedule equations:

iε[1, M]̂t ₁=3i+2M t ₂=3i+3M

The respective scatter domains are thus: 2M+3≦t₁≦5M+2̂3M+3<t₂<6M. This inturn yields, after stretching: 2M+3<t₁<5M+2̂3M+3≦t₂≦6M+2. While theconstraints on t2 have been successfully stretched and will provide lessopportunities for separation with other statements, the ones on t1 couldnot be stretched because of the statically unknown value of 2M %3. Undersuch schedules, the interleaving of the statements changes with thevalues of 2M %3 and cannot be expressed without outermost modulo casedistinction. However, no disruption on the re-entrance stability isexperienced as can be seen from FIGS. 20A-20C. The reason behind thestability is that the stretched loop bounds are parametric and cover allthe different modulo cases with a single expression. The lack ofknowledge of the exact modulo remainder forces the domains to overlapand does not generate spurious cuts.

FIGS. 21-24 are flowcharts that illustrate various operations accordingto the illustrative embodiments. It will be understood that each blockof the flowchart illustrations, and combinations of blocks in theflowchart illustrations, can be implemented by computer programinstructions. These computer program instructions may be provided to aprocessor or other programmable data processing apparatus to produce amachine, such that the instructions which execute on the processor orother programmable data processing apparatus create means forimplementing the functions specified in the flowchart block or blocks.These computer program instructions may also be stored in acomputer-readable memory or storage medium that can direct a processoror other programmable data processing apparatus to function in aparticular manner, such that the instructions stored in thecomputer-readable memory or storage medium produce an article ofmanufacture including instruction means which implement the functionsspecified in the flowchart block or blocks.

Accordingly, blocks of the flowchart illustrations support combinationsof means for performing the specified functions, combinations of stepsfor performing the specified functions and program instruction means forperforming the specified functions. It will also be understood that eachblock of the flowchart illustrations, and combinations of blocks in theflowchart illustrations, can be implemented by special purposehardware-based computer systems which perform the specified functions orsteps, or by combinations of special purpose hardware and computerinstructions.

Furthermore, the flowcharts are provided to demonstrate the operationsperformed within the illustrative embodiments. The flowcharts are notmeant to state or imply limitations with regard to the specificoperations or, more particularly, the order of the operations. Theoperations of the flowcharts may be modified to suit a particularimplementation without departing from the spirit and scope of thepresent invention.

FIG. 21 is a flowchart outlining an exemplary operation for utilizing are-entrance path to obtain further optimization of code in accordancewith one illustrative embodiment. The operation outlined in FIG. 21 maybe performed, for example, by a polyhedral loop optimization mechanism,such as element 800 in FIG. 8 described above. The polyhedral loopoptimization mechanism may work in conjunction with a compiler, such ascompiler 805 in FIG. 8, to optimize source code in an iterative mannerusing a re-entrance path of the illustrative embodiments. The optimizedcode may then be provided back to the compiler 805 for use in generatingexecutable code for execution on a computing device, such as server 304or client 310 in FIG. 3, or the like.

As shown in FIG. 21, the operation starts with source code beingreceived from the compiler (step 2110). A program statement view of thesource code is generated using a known methodology (step 2112). Forexample, as discussed above, a known polyhedral scan operation may beperformed on an intermediate representation of the source code togenerate a program statement view of the source code. One or more loopoptimizations are then optionally performed on the program statementview of the source code (step 2113).

For each statement in the program statement view of the source code,program statement information, such as the Alpha, Beta, and Gammamatrices, the Domain, Access Function(s), and the statement expression,are obtained (step 2114). A scattering matrix is built for eachstatement based on the program statement information (step 2116) and aportion of the program statement information, such as the Alpha, Beta,and Gamma matrices, for example, is stored for later use (step 2118). Itshould be noted that the present invention is in no way limited to aspecific representation of the scheduling function associated with agiven statement. The Alpha, Beta, and Gamma matrix structure is usedherein as one example embodiment for illustrative purposes only. Manyother types of representations may be utilized without departing fromthe spirit and scope of the present invention. For example, otherpossible representations may include a unified matrix representing thescheduling information that maps a specific iteration to a specific(possibly multi-dimensional) date or the like.

A program loop view, or AST, of the source code is generated based onthe program statement view and the scattering matrix (step 2120). Foreach node in the program loop view, a list of statements included in thenode is stored and a reference to each statement's original programstatement information is also stored in association with the node (step2122).

One or more code generation optimizations may be performed on theprogram loop view (step 2124) and a determination is made as to whetherthe re-entrance path is to be taken (step 2126). As mentioned above, thedecision to take the re-entrance path is dependent upon the particularcircumstances and whether or not re-entrance will be beneficial to theoverall optimization of the code. This decision may be made based onuser input or an automated mechanism, as discussed previously above.

If the re-entrance path is not to be taken, then the operationterminates. If the re-entrance path is to be taken, then the statementsin the nodes of the program loop view are split, if possible, intosub-statements upon which loop optimizations may be performedindividually (step 2128). The nodes, which may include the splitsub-statements, are then rescanned to construct new program statementinformation (step 2130). The rescanning of the nodes in the program loopview may involve, for example, selecting a set of boundary nodes. Theset of boundary nodes may be a set of interior nodes (node withchildren) provided none of the interior nodes have parent nodes that arealready a boundary node or a set of leaf nodes (node without children)provided that nod of the leaf nodes have parent nodes that are alreadyboundary nodes. Then for a given boundary node B at depth d in theprogram loop view, for each statement S associated with B, new programstatement information is constructed as follows. The Alpha and Gammamatrices are maintained the same as they were for the original statementS (as stored by step 2118). The Beta matrix is reactualized to reflectthe ordering in the program loop view. For example, if a beta value inthe Beta matrix is 1, the depth d is set to the node number at eachlevel in the program loop view. If a beta value in the Beta matrix has avalue of the depth d+1, the last beta value is set to the correspondingvalue in the original beta values associated with S and stored in theprogram loop view. The domain may then be constructed as the union ofall the domains associated with leaf nodes that contain S and have nodeB as a parent node.

The new program statement information is then used to generate a newprogram statement view of the source code (step 2132). This new programstatement view of the source code may then be subjected to additionalloop optimizations, converted into a new program loop view of the codeto which additional code generation optimizations may be applied, andthe like, in an iterative manner, if desired. The operation then eitherterminates if no further optimization is required or returns to step2113 if further optimization is desired.

It should be noted that the above embodiment is only one possibleapplication of a scheme in which a code generation step (such as the ASTgeneration in step 2120) is used in order to split original statementsfor further optimizations in a Program Statement Representation.Alternative embodiments could simply build an AST and analyze it usingsome generic inspector in order to determine suitable cuts directly inthe original Program Statement Representation. While it is believed thatthe process in FIG. 21 is an efficient way to proceed, such alternativeprocess generating an AST or similar code representation followed by aninspection phase to split statements in the original Program StatementView are equally applicable and suitable in some implementations of thepresent invention.

FIG. 22 is a flowchart outlining an exemplary operation for applying acode generation transformation algorithm in accordance with oneillustrative embodiment. The operation outlined in FIG. 22 may beperformed, for example, as part of the step 2124 in FIG. 21. It shouldbe appreciated that the operation outlined in FIG. 22 may be performedfor each of a plurality of code generation optimizations.

As shown in FIG. 22, the operation starts with receiving the programloop view of the source code (step 2210). This may be obtained, forexample, from step 2122 in FIG. 21. A definition of the types of nodesin the program loop view to which a particular code generationoptimization is to be applied may be generated (step 2220). It should beappreciated that such a definition may have been previously definedprior to the operation outlined in FIG. 22 being executed, for example.The nodes of the program loop view are then traversed to mark the nodesmeeting the definition for the code generation optimization (step 2230).The code generation transformation algorithm is then applied such thatthe code generation optimization core function is applied to thestatements in the marked nodes (step 2240). The operation thenterminates.

The code generation transformation algorithm applied in step 2240 may beof the type shown in FIG. 11, described previously. An alternative codegeneration transformation algorithm may be as shown in the followingpseudocode where AST refers to the program loop view of the source codecurrently undergoing the code generation optimizations:

ApplyCodegenTransformation: applies a transformation on AST  Input : node: AST, where the nodes that initiate a transformation are marked.outer_visitor_type: method that order the nodes of the AST according toits definition (e.g. depth first search, ...) apply_core_function:method to be applied on the marked node propagate_changes: method to beapplied on the children below a marked node Output : transformed ASTvisitor = new visitor(outer_visitor_type, root of AST) for eachcurrentNode in visitor, according to the order defined by theouter_visitor_type if currentNode is marked boolean changed = false 1core_node_list = apply_core_function(currentNode, changed) if changedsort core_node_list under parent context foreach newNode incore_node_list, accorind to the sorted order 2 newNode.children = areplicate copy of currentNode.children 3 newNode =propagate_changes(newNode.children) if newNode.children size is 0 4delete newNode return transformed ASTIt should be appreciated that with the application of the codegeneration transformation algorithm of the illustrative embodiments,rather than having to apply code generation optimizations to the programloop view as a whole, i.e. at only the root of the program loop view, orat all of the nodes at the same depth as a whole, the mechanisms of theillustrative embodiments allow the code generation optimizations to beapplied to individual arbitrary sets of one or more nodes in the programloop view.

FIG. 23 is a flowchart outlining an exemplary operation for preservingstability of code in the presence of conditionals for re-entrance inaccordance with one illustrative embodiment. The operation outlined inFIG. 23 may be performed, for example, as part of step 2130 in FIG. 21to ensure stability of the code, i.e. minimizing growth of the code orcode bloat.

As shown in FIG. 23, the operation starts with receiving the program lopview of the source code (step 2310). A next node in the program loopview is identified in a depth first search order with processing ofparent nodes before child nodes (step 2320). The depth d of the node isretrieved and the immediate parent of the node is identified (step2330). The scattering domain for the node is projected on a depth of 1to d-1 (step 2340) and the projected scattering is simplified under thedomain of the parent node (step 2350). A determination is made as towhether the domain is the universe (step 2360). Stating that a domain isthe universe is equivalent to stating that the domain corresponds to theentire space with no constraints. For example, in the one dimensionalspace of integer or entire numbers, a domain formed by the twoconstrains “x>−5 and x<10” is not the universe as it has constrains.However, if a domain with no constrains is the universe, it includes anypossible integer numbers, from minus infinity to plus infinity. If thedomain is not the universe, then the parent node is marked as a boundarynode (step 2370).

Thereafter, or if the node is the universe, a determination is made asto whether more nodes are present that need to be processed (step 2380).If so, the operation returns to step 2320 and repeats with the nextnode. If no more nodes are to be processed, the operation performs arescan operation (step 2390) such as in step 2130 of FIG. 21. Theoperation then terminates.

FIG. 24 is a flowchart outlining an exemplary operation for performingscatter domain stretching in accordance with one illustrativeembodiment. As shown in FIG. 24, the operation starts with receiving theprogram statement view of the source code with the program statementinformation for the various statements (step 2410). A next statement inthe program statement view to process is identified (step 2412) and aloop depth Ds of the statement is determined (step 2414). The HermiteNormal Form (HNF) matrix for the statement is computed from the Alphamatrix of the statement (step 2416). The scattering matrix Theta for thestatement is computed using the Alpha, Beta, and Gamma matrices and theDomain of the statement (step 2418).

A next time dimension to be processed is identified (step 2420). Astride factor for that time dimension is determined based on the HNFmatrix (step 2422). A determination is made as to whether the stridefactor is greater than one (step 2424). If the stride factor is greaterthan one, then a determination is made as to whether the stride factordivides every component in the scattering matrix for every row thatcontains a non-null time dimension entry Td (step 2426). If so, then foreach domain constraint Cd that includes the time dimension entry Td, ifCd is a lower bound constraint of the form f(time, parameters)>=const,then const is replaced by floor(const−1/Sf)*Sf+1 in the original domainmatrix, where Sf is the scatter factor. If Cd is an upper boundconstraint of the form f(time, parameters)<=const, then const isreplaced by floor((const+1)/Sf)*Sf−1 in the original domain matrix (step2428).

Thereafter, or if the stride factor does not divide every component inthe scattering matrix (step 2426), or if the stride factor is less thanor equal to 1, then a determination is made as to whether there areadditional time dimensions to process (step 2430). If there areadditional time dimensions to process, the operation returns to step2420 and proceeds with the next time dimension. If there are noadditional time dimensions to process, the operation determines if thereare more statements to process (step 2432). If there are more statementsto process, the operation returns to step 2412 and proceeds with thenext statement. If there are no more statements to process, then thescattering matrix Theta is recomputed using the Alpha, Beta, and Gammamatrices and the modified domain (step 2434). The operation thenterminates.

Again, this invention is not constrained to a particular representationof the schedule (the Alpha/Beta/Gamma matrices here). While they areused in the above embodiments, other alternative representations can beused in the illustrative embodiments without departing from the spiritand scope of the present invention, as discussed above.

Thus, the illustrative embodiments provide a mechanism for optimizingsource code that permits individual statement instances within a programloop view of the source code to be operated upon by code generationoptimizations and loop optimizations. A re-entrance path is providedthrough which the code may undergo optimizations in an iterative manner.The re-entrance path allows a program loop view of the code to betransformed back into a program statement view so that program loopoptimizations may be applied to the program statement view after codegeneration optimizations have been applied to the previous program loopview. Moreover, mechanisms are provided for ensuring the stability ofthe code when traversing the re-entrance path by projecting andsimplifying scattering domains, performing polyhedral rescans of thecode based on such scattering domains, and minimizing code bloat.

It should be appreciated that the illustrative embodiments may take theform of an entirely hardware embodiment, an entirely software embodimentor an embodiment containing both hardware and software elements. In oneexemplary embodiment, the mechanisms of the illustrative embodiments areimplemented in software, which includes but is not limited to firmware,resident software, microcode, etc.

Furthermore, the illustrative embodiments may take the form of acomputer program product accessible from a computer-usable orcomputer-readable medium providing program code for use by or inconnection with a computer or any instruction execution system. For thepurposes of this description, a computer-usable or computer-readablemedium can be any apparatus that can contain, store, communicate,propagate, or transport the program for use by or in connection with theinstruction execution system, apparatus, or device.

The medium may be an electronic, magnetic, optical, electromagnetic,infrared, or semiconductor system (or apparatus or device) or apropagation medium. Examples of a computer-readable medium include asemiconductor or solid state memory, magnetic tape, a removable computerdiskette, a random access memory (RAM), a read-only memory (ROM), arigid magnetic disk and an optical disk. Current examples of opticaldisks include compact disk-read-only memory (CD-ROM), compactdisk-read/write (CD-R/W) and DVD.

A data processing system suitable for storing and/or executing programcode will include at least one processor coupled directly or indirectlyto memory elements through a system bus. The memory elements can includelocal memory employed during actual execution of the program code, bulkstorage, and cache memories which provide temporary storage of at leastsome program code in order to reduce the number of times code must beretrieved from bulk storage during execution.

Input/output or I/O devices (including but not limited to keyboards,displays, pointing devices, etc.) can be coupled to the system eitherdirectly or through intervening I/O controllers. Network adapters mayalso be coupled to the system to enable the data processing system tobecome coupled to other data processing systems or remote printers orstorage devices through intervening private or public networks. Modems,cable modems and Ethernet cards are just a few of the currentlyavailable types of network adapters.

The description of the present invention has been presented for purposesof illustration and description, and is not intended to be exhaustive orlimited to the invention in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the art. Theembodiment was chosen and described in order to best explain theprinciples of the invention, the practical application, and to enableothers of ordinary skill in the art to understand the invention forvarious embodiments with various modifications as are suited to theparticular use contemplated.

1. A method, in a data processing system, for optimizing program code,comprising: receiving source code for a program in a compiler; andoptimizing, in a loop optimization engine, the source code for executionby a computing device, wherein optimizing the source code comprises:generating a program statement view of the source code; generating aprogram loop view of the source code based on the program statementview; applying one or more code generation optimizations to the programloop view of the source code to generate an optimized program loop viewof the source code; converting the optimized program loop view of thesource code back into a first optimized program statement view of thesource code through a re-entrance path; performing one or moreadditional optimizations on the first optimized program statement viewof the source code; and outputting resulting optimized code, as a resultof optimizing the source code, to the compiler for generation ofexecutable code to be executed on a computing device.
 2. The method ofclaim 1, wherein the one or more code generation optimizations areapplied to individual nodes within the program loop view of the sourcecode.
 3. The method of claim 1, wherein the one or more code generationoptimizations result in a lower control flow overhead of the optimizedprogram loop view of the source code when compared to control flowoverhead of the program loop view of the source code, and wherein theone or more code generation optimizations do not modify a program orderof statements in the optimized program loop view from a program orderpresent in the program statement view of the source code.
 4. The methodof claim 1, wherein converting the optimized program loop view of thesource code into a first optimized program statement view of the sourcecode through a re-entrance path comprises: retrieving an Alpha matrix, aBeta matrix, and a Gamma matrix for each statement in the optimizedprogram loop view; and transforming the optimized program loop view intothe first optimized program statement view using the Alpha, Beta, andGamma matrices along with a remapping matrix that identifies how totransform the optimized program loop view back to a program statementview, wherein the Alpha matrix represents a speed at which an associatedstatement is performed along a given time dimension, the Beta matrixrepresents a sequential interleaving of the associated statement alongdifferent loop depths, and the Gamma matrix represents a constantparametric shifting of the associated statement along each timedimension.
 5. The method of claim 1, applying one or more codegeneration optimizations to the program loop view of the source code togenerate an optimized program loop view of the source code comprises:for each statement in the optimized program loop view, splitting adomain and schedule of the statement into a plurality of sub-domains andsub-schedules based on instances of the statement in the optimizedprogram loop view such that the statement does not share a commonrepresentation with other statements in the first optimized programstatement view, wherein the one or more additional optimizations areapplied to each statement individually based on the separate sub-domainsand sub-schedules.
 6. The method of claim 5, wherein applying one ormore code generation optimizations to the program loop view of thesource code to generate an optimized program loop view of the sourcecode further comprises: generating a domain and schedule for a kernel ofthe statements of the optimized program loop view, wherein the domainand schedule for the kernel are separate from the sub-domain andsub-schedules of the instances of the statements.
 7. The method of claim5, wherein the sub-domains and sub-schedules are generated by extractinga kernel of fused statements in the optimized program loop view suchthat a separate domain and schedule for each boundary portion of thefused statements, where only one statement applies, is generated, and aseparate domain and schedule for the kernel, where both statementsapply, is generated.
 8. The method of claim 1, wherein the one or morecode generation optimizations comprise at least one of simplificationand unstretching, if hoisting, substitute modulo, or loop unrolling. 9.The method of claim 1, wherein generating a program statement view ofthe source code comprises performing a polyhedral scan operation on thesource code to generate the program statement view, and wherein there-entrance path comprises a polyhedral rescan module that rescans theoptimized program loop view of the source code to generate the firstoptimized program statement view from the optimized program loop view.10. The method of claim 1, wherein performing one or more additionaloptimizations on the first optimized program statement view of thesource code results in a second optimized program statement view of thesource code, and wherein the method further comprises: converting thesecond optimized program statement view of the source code into a secondprogram loop view of the source code; and applying the one or more codegeneration optimizations to the second program loop view to generate asecond optimized program loop view of the source code.
 11. A computerprogram product comprising a computer useable medium having a computerreadable program, wherein the computer readable program, when executedon a computing device, causes the computing device to: receive sourcecode for a program in a compiler; and optimize, in a loop optimizationengine, the source code for execution by a computing device, whereinoptimizing the source code comprises: generating a program statementview of the source code; generating a program loop view of the sourcecode based on the program statement view; applying one or more codegeneration optimizations to the program loop view of the source code togenerate an optimized program loop view of the source code; convertingthe optimized program loop view of the source code back into a firstoptimized program statement view of the source code through are-entrance path; performing one or more additional optimizations on thefirst optimized program statement view of the source code; andoutputting resulting optimized code, as a result of optimizing thesource code, to the compiler for generation of executable code to beexecuted on a computing device.
 12. The computer program product ofclaim 11, wherein the one or more code generation optimizations areapplied to individual nodes within the program loop view of the sourcecode.
 13. The computer program product of claim 11, wherein the one ormore code generation optimizations result in a lower control flowoverhead of the optimized program loop view of the source code whencompared to control flow overhead of the program loop view of the sourcecode, and wherein the one or more code generation optimizations do notmodify a program order of statements in the optimized program loop viewfrom a program order present in the program statement view of the sourcecode.
 14. The computer program product of claim 11, wherein convertingthe optimized program loop view of the source code into a firstoptimized program statement view of the source code through are-entrance path comprises: retrieving an Alpha matrix, a Beta matrix,and a Gamma matrix for each statement in the optimized program loopview; and transforming the optimized program loop view into the firstoptimized program statement view using the Alpha, Beta, and Gammamatrices along with a remapping matrix that identifies how to transformthe optimized program loop view back to a program statement view,wherein the Alpha matrix represents a speed at which an associatedstatement is performed along a given time dimension, the Beta matrixrepresents a sequential interleaving of the associated statement alongdifferent loop depths, and the Gamma matrix represents a constantparametric shifting of the associated statement along each timedimension.
 15. The computer program product of claim 11, applying one ormore code generation optimizations to the program loop view of thesource code to generate an optimized program loop view of the sourcecode comprises: for each statement in the optimized program loop view,splitting a domain and schedule of the statement into a plurality ofsub-domains and sub-schedules based on instances of the statement in theoptimized program loop view such that the statement does not share acommon representation with other statements in the first optimizedprogram statement view, wherein the one or more additional optimizationsare applied to each statement individually based on the separatesub-domains and sub-schedules.
 16. The computer program product of claim15, wherein applying one or more code generation optimizations to theprogram loop view of the source code to generate an optimized programloop view of the source code further comprises: generating a domain andschedule for a kernel of the statements of the optimized program loopview, wherein the domain and schedule for the kernel are separate fromthe sub-domain and sub-schedules of the instances of the statements. 17.The computer program product of claim 15, wherein the sub-domains andsub-schedules are generated by extracting a kernel of fused statementsin the optimized program loop view such that a separate domain andschedule for each boundary portion of the fused statements, where onlyone statement applies, is generated, and a separate domain and schedulefor the kernel, where both statements apply, is generated.
 18. Thecomputer program product of claim 11, wherein the one or more codegeneration optimizations comprise at least one of simplification andunstretching, if hoisting, substitute modulo, or loop unrolling.
 19. Thecomputer program product of claim 11, wherein generating a programstatement view of the source code comprises performing a polyhedral scanoperation on the source code to generate the program statement view, andwherein the re-entrance path comprises a polyhedral rescan module thatrescans the optimized program loop view of the source code to generatethe first optimized program statement view from the optimized programloop view.
 20. A system, comprising: a processor; and a memory coupledto the processor, wherein the memory comprises instructions which, whenexecuted by the processor, cause the processor to: receive source codefor a program in a compiler executing in the processor; and optimize, ina loop optimization engine associated with the compiler, the source codefor execution by a computing device, wherein optimizing the source codecomprises: generating a program statement view of the source code;generating a program loop view of the source code based on the programstatement view; applying one or more code generation optimizations tothe program loop view of the source code to generate an optimizedprogram loop view of the source code; converting the optimized programloop view of the source code back into a first optimized programstatement view of the source code through a re-entrance path; performingone or more additional optimizations on the first optimized programstatement view of the source code; and outputting resulting optimizedcode, as a result of optimizing the source code, to the compiler forgeneration of executable code to be executed on a computing device.